summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-10-13 16:16:10 +0100
committerGitHub <noreply@github.com>2020-10-13 17:16:10 +0200
commitd0c2714c033b010cbd174138638881dc65abef06 (patch)
treec070bfb3efd05719bf3b2906a8ec7e69a3963fec
parentbbf7b2ee72ae7dede26e4ef48b384404525f389e (diff)
fix(op_crates/web/url): apply backslash replacement to the pathname setter (#7937)
-rw-r--r--cli/tests/unit/url_test.ts2
-rw-r--r--op_crates/web/11_url.js6
2 files changed, 6 insertions, 2 deletions
diff --git a/cli/tests/unit/url_test.ts b/cli/tests/unit/url_test.ts
index e9632c7de..7c8cd3796 100644
--- a/cli/tests/unit/url_test.ts
+++ b/cli/tests/unit/url_test.ts
@@ -192,6 +192,8 @@ unitTest(function urlModifyPathname(): void {
// deno-lint-ignore no-self-assign
url.pathname = url.pathname;
assertEquals(url.pathname, "/baz%23qat%20qux");
+ url.pathname = "\\a\\b\\c";
+ assertEquals(url.pathname, "/a/b/c");
});
unitTest(function urlModifyHash(): void {
diff --git a/op_crates/web/11_url.js b/op_crates/web/11_url.js
index fe7ef041a..f2d12f5be 100644
--- a/op_crates/web/11_url.js
+++ b/op_crates/web/11_url.js
@@ -378,7 +378,7 @@
return null;
}
[parts.path, restUrl] = takePattern(restUrl, /^([^?#]*)/);
- parts.path = encodePathname(parts.path.replace(/\\/g, "/"));
+ parts.path = encodePathname(parts.path);
if (usedNonBase) {
parts.path = normalizePath(parts.path, parts.protocol == "file");
} else {
@@ -870,7 +870,9 @@
}
function encodePathname(s) {
- return [...s].map((c) => (charInPathSet(c) ? encodeChar(c) : c)).join("");
+ return [...s.replace(/\\/g, "/")].map((
+ c,
+ ) => (charInPathSet(c) ? encodeChar(c) : c)).join("");
}
function encodeSearch(s, isSpecial) {