From 47f4070ea63f4ecbb4a8d72cc5fbb8532e86930e Mon Sep 17 00:00:00 2001 From: Petr Kolonicz <72889112+hexrw@users.noreply.github.com> Date: Mon, 5 Feb 2024 13:26:15 +0100 Subject: [PATCH] fix(encodeQueryValue): encode the slash character (#198) --- src/encoding.ts | 1 + test/encoding.test.ts | 2 +- test/normalize.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/encoding.ts b/src/encoding.ts index 7a34e1f8..3ab3b958 100644 --- a/src/encoding.ts +++ b/src/encoding.ts @@ -61,6 +61,7 @@ export function encodeQueryValue(input: QueryValue): string { .replace(AMPERSAND_RE, "%26") .replace(ENC_BACKTICK_RE, "`") .replace(ENC_CARET_RE, "^") + .replace(SLASH_RE, "%2F") ); } diff --git a/test/encoding.test.ts b/test/encoding.test.ts index b413322f..60b86796 100644 --- a/test/encoding.test.ts +++ b/test/encoding.test.ts @@ -95,7 +95,7 @@ describe("encodeQueryValue", () => { }, { input: "!@#$%^&*()_+{}[]|\\:;<>,./?", - out: "!@%23$%25^%26*()_%2B%7B%7D%5B%5D|%5C:;%3C%3E,./?", + out: "!@%23$%25^%26*()_%2B%7B%7D%5B%5D|%5C:;%3C%3E,.%2F?", }, ]; diff --git a/test/normalize.test.ts b/test/normalize.test.ts index 176174eb..ea27a02f 100644 --- a/test/normalize.test.ts +++ b/test/normalize.test.ts @@ -30,8 +30,8 @@ describe("normalizeURL", () => { "/http:/": "/http:/", "http://[2001:db8:85a3:8d3:1319:8a2e:370:7348]/": "http://[2001:db8:85a3:8d3:1319:8a2e:370:7348]/", - "http://localhost/?redirect=http://google.com?q=test": - "http://localhost/?redirect=http://google.com?q=test", + "http://localhost/?redirect=http:%2F%2Fgoogle.com?q=test": + "http://localhost/?redirect=http:%2F%2Fgoogle.com?q=test", "http://localhost/?email=some+v1@email.com": "http://localhost/?email=some+v1@email.com", "http://localhost/?email=some%2Bv1%40email.com":