- From: Karl <notifications@github.com>
- Date: Sat, 28 Jan 2023 14:08:00 -0800
- To: whatwg/url <url@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/url/issues/732/1407498153@github.com>
If we treated pairs with no key-value delimiter as having a `null` value, I think we would also have to accept that in the URL `http://example/foo&&&baz&&another`, the key-value pairs are: ``` key: "foo", value: null key: "", value: null key: "", value: null key: "baz", value: null key: "", value: null key: "another", value: null ``` In other words, we would not be able to skip strings of empty pair delimiters (`&&&&`). AFAICT, that skipping is widely agreed upon by other URL/querystring libraries, so this would be a significant departure. To illustrate why we would need to do that: I have an API which allows identifying each key-value pair by its position (i.e. an index) and supports index-based operations such as inserting pairs at a particular location, replacing a region of pairs, removing a particular pair, or changing the key/value of a particular pair. Now consider the URL `http://example/?foo&baz&another#frag`. The API allows replacing the key component of the first pair: ``` url.queryParams.replaceKey(at: 0, with: "new_key") // result: http://example/?new_key&baz&another#frag // ^^^^^^^ ``` But if you replace the key with the empty string, something interesting happens: ``` url.queryParams.replaceKey(at: 0, with: "") // result: http://example/?=&baz&another#frag // ^ ``` Since empty strings of delimiters are usually skipped entirely, we must insert an `=` sign in order to preserve the fact that the first pair exists and its key is the empty string. Currently this is fine, because the presence or not of the `=` sign does not change the value component. If we started to started to say that the presence of that delimiter is meaningful, then inserting this `=` would also change the pair's value. The only way around it would be allow the following result: ``` url.queryParams.replaceKey(at: 0, with: "") // result: http://example/?&baz&another#frag // ^ ``` And to say that this initial `&` is actually a pair with `(key: "", value: null)`. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/url/issues/732#issuecomment-1407498153 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/url/issues/732/1407498153@github.com>
Received on Saturday, 28 January 2023 22:08:12 UTC