aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gleam_stdlib.mjs11
-rw-r--r--test/gleam/uri_test.gleam3
2 files changed, 11 insertions, 3 deletions
diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs
index 157f66d..3296b67 100644
--- a/src/gleam_stdlib.mjs
+++ b/src/gleam_stdlib.mjs
@@ -479,6 +479,10 @@ export function map_insert(key, value, map) {
}
function unsafe_percent_decode(string) {
+ return decodeURIComponent(string || "");
+}
+
+function unsafe_percent_decode_query(string) {
return decodeURIComponent((string || "").replace("+", " "));
}
@@ -491,7 +495,7 @@ export function percent_decode(string) {
}
export function percent_encode(string) {
- return encodeURIComponent(string);
+ return encodeURIComponent(string).replace("%2B", "+");
}
export function parse_query(query) {
@@ -500,7 +504,10 @@ export function parse_query(query) {
for (const section of query.split("&")) {
const [key, value] = section.split("=");
if (!key) continue;
- pairs.push([unsafe_percent_decode(key), unsafe_percent_decode(value)]);
+
+ const decodedKey = unsafe_percent_decode_query(key)
+ const decodedValue = unsafe_percent_decode_query(value)
+ pairs.push([decodedKey, decodedValue])
}
return new Ok(List.fromArray(pairs));
} catch {
diff --git a/test/gleam/uri_test.gleam b/test/gleam/uri_test.gleam
index 2d2732a..267c0d4 100644
--- a/test/gleam/uri_test.gleam
+++ b/test/gleam/uri_test.gleam
@@ -345,7 +345,8 @@ const percent_codec_fixtures = [
#("?", "%3F"), #("'", "'"), #("(", "("), #(")", ")"), #("[", "%5B"),
#("@", "%40"), #("/", "%2F"), #("\\", "%5C"), #("&", "%26"), #("#", "%23"),
#("=", "%3D"), #("~", "~"), #("ñ", "%C3%B1"), #("-", "-"), #("_", "_"),
- #(".", "."), #("*", "*"), #("100% great", "100%25%20great"),
+ #(".", "."), #("*", "*"), #("+", "+"),
+ #("100% great+fun", "100%25%20great+fun"),
]
// Allowed chars