- From: Joyee Cheung <notifications@github.com>
- Date: Mon, 13 Feb 2017 22:21:32 -0800
- To: whatwg/url <url@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/url/issues/248@github.com>
This question comes from the Node.js implementation, refs: https://github.com/nodejs/node/issues/11093 The `URL` constructor specifies: > Set <var>result</var>'s <a for=URL>query object</a> to a <a for=URLSearchParams>new</a> {{URLSearchParams}} object using <var>query</var>, and then set that <a for=URL>query object</a>'s <a for=URLSearchParams>url object</a> to <var>result</var> And the `URLSearchParams` constructor specifies: > If <var>init</var> is given, is a string, and starts with "<code>?</code>", remove the first code point from <var>init</var>. But referencing the getter spec of `url.search`: > Return "<code>?</code>", followed by <a>context object</a>'s <a for=URL>url</a>'s <a for=url>query</a>. one can infer that the `query` of an url should not have the leading `?`, this means: 1. The URL constructor would pass an query with leading `?` stripped to `new URLSearchParams` 2. The `new URLSearchParams` would strip a leading `?` again, in any, but the WPT tests expect `??a=b&c=d` to be serialized as `%3Fa=b&c=d` AFAICT the `URL` constructor should prepend a `?` here, if we don't introduce a special way to notify the `URLSearchParams` constructor not to strip the leading `?`: ```diff diff --git a/url.bs b/url.bs index 7988aa2..f1a9c9d 100644 --- a/url.bs +++ b/url.bs @@ -2648,7 +2648,8 @@ when invoked, must run these steps: <li><p>Set <var>result</var>'s <a for=URL>url</a> to <var>parsedURL</var>. <li><p>Set <var>result</var>'s <a for=URL>query object</a> to a <a for=URLSearchParams>new</a> - {{URLSearchParams}} object using <var>query</var>, and then set that <a for=URL>query object</a>'s + {{URLSearchParams}} object using <var>query</var> prepended with the + leading <code>?</code>, and then set that <a for=URL>query object</a>'s <a for=URLSearchParams>url object</a> to <var>result</var>. <li><p>Return <var>result</var>. ``` Also the definition of `url.query` in `4.1. URL representation` can be a little bit more explicit about the leading `?`. I can put up a PR if this is confirmed. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/url/issues/248
Received on Tuesday, 14 February 2017 06:22:04 UTC