From 2d5740c86a31509dd3e9368d6de848e00b0f2c4d Mon Sep 17 00:00:00 2001 From: sublimemm Date: Thu, 16 Jan 2025 10:05:30 -0500 Subject: [PATCH 1/5] URLSearchParam.append Encoding Behavior Documenting URLSearchParam.append Encoding Behavior and adding an example. --- .../web/api/urlsearchparams/append/index.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/files/en-us/web/api/urlsearchparams/append/index.md b/files/en-us/web/api/urlsearchparams/append/index.md index a18a4b190bd85e9..7704726b0e2d7a5 100644 --- a/files/en-us/web/api/urlsearchparams/append/index.md +++ b/files/en-us/web/api/urlsearchparams/append/index.md @@ -14,6 +14,10 @@ interface appends a specified key/value pair as a new search parameter. As shown in the example below, if the same key is appended multiple times it will appear in the parameter string multiple times for each value. +As shown in the second example below, both `name` and `value` will be automatically +encoded to be URL safe. + + ## Syntax ```js-nolint @@ -34,6 +38,8 @@ None ({{jsxref("undefined")}}). ## Examples ```js +//Example: Adding the same param multiple times + let url = new URL("https://example.com?foo=1&bar=2"); let params = new URLSearchParams(url.search); @@ -42,6 +48,17 @@ params.append("foo", 4); //Query string is now: 'foo=1&bar=2&foo=4' ``` +```js +//Example: Demostrating the encoding behavior + +const params = new URLSearchParams(); + +params.append('needsEncoding$%&$#@++++++','needsEncoding$#&*@#()+++++' ) +params.toString(); +//"needsEncoding%24%25%26%24%23%40%2B%2B%2B%2B%2B%2B=needsEncoding%24%23%26*%40%23%28%29%2B%2B%2B%2B%2B" + +``` + ## Specifications {{Specifications}} From 3611d0a4013245cdc65f5fb28b8bf055d81da3d4 Mon Sep 17 00:00:00 2001 From: sublimemm Date: Thu, 16 Jan 2025 10:10:17 -0500 Subject: [PATCH 2/5] lint Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- files/en-us/web/api/urlsearchparams/append/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/api/urlsearchparams/append/index.md b/files/en-us/web/api/urlsearchparams/append/index.md index 7704726b0e2d7a5..cc21ad371c324c6 100644 --- a/files/en-us/web/api/urlsearchparams/append/index.md +++ b/files/en-us/web/api/urlsearchparams/append/index.md @@ -14,7 +14,7 @@ interface appends a specified key/value pair as a new search parameter. As shown in the example below, if the same key is appended multiple times it will appear in the parameter string multiple times for each value. -As shown in the second example below, both `name` and `value` will be automatically +As shown in the second example below, both `name` and `value` will be automatically encoded to be URL safe. From f87ec13618b92f903927c94c5a550eacadd85982 Mon Sep 17 00:00:00 2001 From: sublimemm Date: Thu, 16 Jan 2025 10:10:27 -0500 Subject: [PATCH 3/5] lint Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- files/en-us/web/api/urlsearchparams/append/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/files/en-us/web/api/urlsearchparams/append/index.md b/files/en-us/web/api/urlsearchparams/append/index.md index cc21ad371c324c6..30fcf9617130208 100644 --- a/files/en-us/web/api/urlsearchparams/append/index.md +++ b/files/en-us/web/api/urlsearchparams/append/index.md @@ -17,7 +17,6 @@ appear in the parameter string multiple times for each value. As shown in the second example below, both `name` and `value` will be automatically encoded to be URL safe. - ## Syntax ```js-nolint From 7e8e76ee66f621fac9e204ae33965a1b977c83d4 Mon Sep 17 00:00:00 2001 From: sublimemm Date: Thu, 16 Jan 2025 10:10:41 -0500 Subject: [PATCH 4/5] lint Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- files/en-us/web/api/urlsearchparams/append/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/api/urlsearchparams/append/index.md b/files/en-us/web/api/urlsearchparams/append/index.md index 30fcf9617130208..808e38f9bfca9ff 100644 --- a/files/en-us/web/api/urlsearchparams/append/index.md +++ b/files/en-us/web/api/urlsearchparams/append/index.md @@ -52,7 +52,7 @@ params.append("foo", 4); const params = new URLSearchParams(); -params.append('needsEncoding$%&$#@++++++','needsEncoding$#&*@#()+++++' ) +params.append("needsEncoding$%&$#@++++++", "needsEncoding$#&*@#()+++++"); params.toString(); //"needsEncoding%24%25%26%24%23%40%2B%2B%2B%2B%2B%2B=needsEncoding%24%23%26*%40%23%28%29%2B%2B%2B%2B%2B" From 6a289a2ff28a6d24cfdfdd158635790caeaebfde Mon Sep 17 00:00:00 2001 From: sublimemm Date: Thu, 16 Jan 2025 10:10:52 -0500 Subject: [PATCH 5/5] lint Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- files/en-us/web/api/urlsearchparams/append/index.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/files/en-us/web/api/urlsearchparams/append/index.md b/files/en-us/web/api/urlsearchparams/append/index.md index 808e38f9bfca9ff..98d531076d2d377 100644 --- a/files/en-us/web/api/urlsearchparams/append/index.md +++ b/files/en-us/web/api/urlsearchparams/append/index.md @@ -54,8 +54,7 @@ const params = new URLSearchParams(); params.append("needsEncoding$%&$#@++++++", "needsEncoding$#&*@#()+++++"); params.toString(); -//"needsEncoding%24%25%26%24%23%40%2B%2B%2B%2B%2B%2B=needsEncoding%24%23%26*%40%23%28%29%2B%2B%2B%2B%2B" - +//"needsEncoding%24%25%26%24%23%40%2B%2B%2B%2B%2B%2B=needsEncoding%24%23%26*%40%23%28%29%2B%2B%2B%2B%2B" ``` ## Specifications