Skip to content

Commit f668f19

Browse files
yoshi-monsterlpil
authored andcommitted
add test, make erlang and javascript implementation agree #672
1 parent fab4557 commit f668f19

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/gleam_stdlib.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ export function map_insert(key, value, map) {
479479
}
480480

481481
function unsafe_percent_decode(string) {
482+
return decodeURIComponent(string || "");
483+
}
484+
485+
function unsafe_percent_decode_query(string) {
482486
return decodeURIComponent((string || "").replace("+", " "));
483487
}
484488

@@ -491,7 +495,7 @@ export function percent_decode(string) {
491495
}
492496

493497
export function percent_encode(string) {
494-
return encodeURIComponent(string);
498+
return encodeURIComponent(string).replace("%2B", "+");
495499
}
496500

497501
export function parse_query(query) {
@@ -500,7 +504,10 @@ export function parse_query(query) {
500504
for (const section of query.split("&")) {
501505
const [key, value] = section.split("=");
502506
if (!key) continue;
503-
pairs.push([unsafe_percent_decode(key), unsafe_percent_decode(value)]);
507+
508+
const decodedKey = unsafe_percent_decode_query(key)
509+
const decodedValue = unsafe_percent_decode_query(value)
510+
pairs.push([decodedKey, decodedValue])
504511
}
505512
return new Ok(List.fromArray(pairs));
506513
} catch {

test/gleam/uri_test.gleam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ const percent_codec_fixtures = [
345345
#("?", "%3F"), #("'", "'"), #("(", "("), #(")", ")"), #("[", "%5B"),
346346
#("@", "%40"), #("/", "%2F"), #("\\", "%5C"), #("&", "%26"), #("#", "%23"),
347347
#("=", "%3D"), #("~", "~"), #("ñ", "%C3%B1"), #("-", "-"), #("_", "_"),
348-
#(".", "."), #("*", "*"), #("100% great", "100%25%20great"),
348+
#(".", "."), #("*", "*"), #("+", "+"),
349+
#("100% great+fun", "100%25%20great+fun"),
349350
]
350351

351352
// Allowed chars

0 commit comments

Comments
 (0)