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 26930 - Some correct around URLSearchParams
Summary: Some correct around URLSearchParams
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-09-29 15:25 UTC by Arkadiusz Michalski (Spirit)
Modified: 2014-10-02 14:09 UTC (History)
1 user (show)

See Also:


Attachments

Description Arkadiusz Michalski (Spirit) 2014-09-29 15:25:48 UTC
Hi, I report a few more things that can be improved/correct:

===

In algo "new URLSearchParams object":

3. If init is a string, set query's associated list of name-value pairs to the result of parsing input. << not "parsing input" but "parsing init".

===

For all URLSearchParams's method algo should be more precise, look one example for remove():
1. Remove all name-value pairs whose name is name. << we don't know what is pairs, where pairs belong to.

Maybe you should make term (with ID) for asociated list in:
"A URLSearchParams object has an associated list of name-value pairs called list n-v, which is initially empty."

and write this:
1. Remove all name-value pairs from list n-v of context object whose name is name. << or somethin simillar

But such inaccuracy exists in the commands of other interfaces. Only one is enaught precise (Setting the href attribute must run these steps):
2. If the context object is a URL object and its url is null, throw a TypeError exception. 

===

Algo "application/x-www-form-urlencoded serializer" takes a list of name-value pairs pairs. What its exactly means? Take copy of that list or operate on original list?

I ask because in some steps I see this:

3. For each pair in pairs, run these substeps:
 3.1 Replace pair's name and value with the result of running encode on them using encoding override, respectively.
 3.2. Replace pair's name and value with their serialization. 

So "replace pairs's name" and replace "pair's value" means that we modificate a original list? Or we should get only string value of pair's name and pair's value, replace only this strings and add them to output?

===

And last, how treat argument (or arguments) passing to URLSearchParams's methods? 

Look, I analize only  append(name, value):
1. Append a new name-value pair whose name is name and value is value, to the list of name-value pairs.

But name and value should be encode/decode, percent encode/decode, etc. before append to list? When we use constructor URLSearchParams() we see that step:
3. If init is a string, set query's associated list of name-value pairs to the result of parsing input.

I check this in Firefox (now only this browser support URLSearchParams interface):

<script>
 var new_USP1 = new URLSearchParams("$=%C4%87");

 document.write(new_USP1); // "%24=%C4%87"

 document.write("<br>");

 var new_USP2 = new URLSearchParams("");
 new_USP2.append("$", "%C4%87");

 document.write(new_USP2); "%24=%25C4%2587"
</script>

We see that Firefox for append() change "%" to "%25" but for constructor don't do this. Alghoritms for URLSearchParams's methods don't mention anything about transform arguments (and it's hard to determine the correct behavior). In the other site, when use simillar command (like URLSearchParams(), setting URLUtils.search or URLUtils.href) its happend.
Comment 1 Anne 2014-09-30 13:58:12 UTC
That's a lot in one bug...

https://github.com/whatwg/url/commit/8770789a8583bf356d3dcedab8d1ad0bd69b53fb

... has fixes for the first two problems.


# What its exactly means? 
# Take copy of that list or operate on original list?

That's a good question. The algorithm should make a copy I think.


# And last, how treat argument (or arguments) 
# passing to URLSearchParams's methods? 

There should be no special handling. Only when parsing and serializing have special handling. The actual contents are "decoded", so to say.
Comment 2 Arkadiusz Michalski (Spirit) 2014-09-30 14:40:58 UTC
(In reply to Anne from comment #1)

> That's a lot in one bug...

If necessary can be split:)

> There should be no special handling. Only when parsing and serializing have
> special handling. The actual contents are "decoded", so to say.

Ok, now understand this difference, I will check this methods in Firefox.
Comment 3 Arkadiusz Michalski (Spirit) 2014-10-01 13:58:01 UTC
Anne, after  "Make URLSearchParams’s list explicit" you can also change "list of name-value pairs" to "list" and refer to it in:

- set the input (step 5.2 and 6.)
- setting search (step 2. and 6.)
- setting searchParams (step 5.)
Comment 5 Arkadiusz Michalski (Spirit) 2014-10-02 12:55:42 UTC
> Anything else?

Hmm maybe explicitly add the initial values​​ in some cases:

https://url.spec.whatwg.org/#concept-urlsearchparams-url-object
"A URLSearchParams object has an associated list of zero or more url objects" << add ", which is initially empty."

https://url.spec.whatwg.org/#concept-url-fragment
Add "It is initially null."

https://url.spec.whatwg.org/#concept-url-object
Add "It is initially null."

https://url.spec.whatwg.org/#concept-urlutils-query-object
This should has initial value too, maybe here:
"Unless stated otherwise, query encoding is utf-8." << add " and query object is null."