diff --git a/url.bs b/url.bs index 8d51dbbe..f26b2ac4 100644 --- a/url.bs +++ b/url.bs @@ -2305,6 +2305,7 @@ string input, optionally with a base URL base, opti
byte is 0x22 ("), 0x23 (#), 0x3C (<), or 0x3E (>)
byte is 0x27 (') and url is special +
then append byte, percent encoded, to url's query. @@ -2669,15 +2670,17 @@ takes a byte sequence input and then runs these steps:
Return output. + less than 0x20 SP, + 0x21 (!) to 0x29 (right parenthesis), + 0x2B (+), + 0x2C (,), + 0x2F (/), + 0x3A (:) to 0x40 (@), + 0x5B ([) to 0x5E (^), + 0x60 (`), + bytes greater than 0x7A (z). With a special case for 0x20 (SP). + + Do not change this without double checking URLENCODED-UNITS -->
The
application/x-www-form-urlencoded
serializer
@@ -3102,6 +3105,38 @@ let params = new URLSearchParams({key: "730d67"})
params.toString() // "key=730d67"
+
As a {{URLSearchParams}} object uses the application/x-www-form-urlencoded
+ format underneath there are some difference with how it encodes certain code points compared to a
+ {{URL}} object (including {{URL/href}} and {{URL/search}}). This can be especially surprising when
+ using {{URL/searchParams}} to operate on a URL's query.
+
+
+const url = new URL('https://example.com/?a=b ~');
+console.log(url.href); // "https://example.com/?a=b%20~"
+url.searchParams.sort();
+console.log(url.href); // "https://example.com/?a=b+%7E"
+
+
+const url = new URL('https://example.com/?a=~&b=%7E');
+console.log(url.search); // "?a=~&b=%7E"
+console.log(url.searchParams.get('a')); // "~"
+console.log(url.searchParams.get('b')); // "~"
+
+ {{URLSearchParams}} objects will percent-encode: U+0000 NULL to U+0019 END OF MEDIUM, inclusive, + U+0021 (!) to U+0029 RIGHT PARENTHESIS, inclusive, U+002B (+), U+002C (,), U+002F (/), U+003A (:) + to U+0040 (@), inclusive, U+005B ([) to U+005E (^), inclusive, U+0060 (`), and anything greater + than U+007A (z). And will encode U+0020 SPACE as U+002B (+). + + +
Ignoring encodings (use UTF-8), {{URL/search}} will percent-encode U+0000 NULL to + U+0020 SPACE, inclusive, U+0022 ("), U+0023 (#), U+0027 (') varying on is special, + U+003C (<), U+003E (>), and anything greater than U+007E (~). + +
A {{URLSearchParams}} object has an associated list of name-value pairs, which is initially empty.