This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27065 - searchParams attribute should always return URLSearchParams object or sometimes null?
Summary: searchParams attribute should always return URLSearchParams object or sometim...
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: URL (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: Unsorted
Assignee: Anne
QA Contact: sideshowbarker+urlspec
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-15 21:06 UTC by Arkadiusz Michalski (Spirit)
Modified: 2014-10-16 11:32 UTC (History)
1 user (show)

See Also:


Attachments

Description Arkadiusz Michalski (Spirit) 2014-10-15 21:06:56 UTC
I mention about this in bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=27022#c1.

Now only Firefox support URLSearchParams so examples will presents result only for this browser. There still is space for corect this browser or change something in URL spec.

By spec "query object" can be set from null to URLSearchParams when "set the input" is used. In some case null will stay, but in IDL I don't see nullable type for .searchParams. 

Simple case:

var someURL = new URL("aaa:bbb");

If I understand all algos, then this step from "set the input":
  5. If url is non-null and its relative flag is set, run these substeps
will be never executed and "query object" stay with null (initial value) and someURL.searchParams should return null.

Next case is important for HTML, how treat this:

<a>
<a href="parserReturnError">

a.searchParams should return null or URLSearchParams object with empty list?
Now HTML denided this wrong (https://www.w3.org/Bugs/Public/show_bug.cgi?id=27047) but before correct HTML, URL spec should be correct.

What can I add is that Firefox always create URLSearchParams.

<a id="a1"></a>
<a id="a2" href></a>
<a id="a3" href="abc:def"></a>

<script>

 var a1 = document.getElementById("a1");
 var a2 = document.getElementById("a2"); // the same as href="" and probably use base URL
 var a3 = document.getElementById("a3");

 var a4 = new URL("abc:def");

 document.write(a1.searchParams.append + "<br><br>"); // function append() { [native code] }

 document.write(a2.searchParams.append + "<br><br>"); // function append() { [native code] }

 document.write(a3.searchParams.append + "<br><br>"); // function append() { [native code] }

 document.write(a4.searchParams.append + "<br><br>"); // function append() { [native code] }

</script>

This is still fresh and can be easy correct (by URL spec or Firefox) but its important what behaviour is excepted.
Comment 1 Arkadiusz Michalski (Spirit) 2014-10-15 22:37:51 UTC
Now I realize that this in "set the input" is strange:

 5. If url is non-null and its relative flag is set, run these substeps...

Why "relative flag" is used here? Non-relative URL can have query (and set/get by search property). So when "set the input" is used for this URL then URLSearchParams shuld be create too and let us to easy manipulate query.

Can't show this behaviour in actual browser because Firefox doesn't set query and Chrome set (but doesn't support URLSearchParams).

<script>

 var someURL = new URL("abc:def?a=b");

 document.write(someURL.search + "<br><br>"); // Chrome "?aa", Firefox ""

 someURL.search = "test";

 document.write(someURL.search + "<br><br>"); // Chrome "?test", Firefox ""

</script>