mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
fix(URL): Don't encode "'" in non-special query strings (#7152)
This commit is contained in:
parent
29e3f4cd3a
commit
d444bd89db
2 changed files with 20 additions and 13 deletions
|
@ -370,7 +370,7 @@
|
||||||
}
|
}
|
||||||
if (usedNonBase || restUrl.startsWith("?")) {
|
if (usedNonBase || restUrl.startsWith("?")) {
|
||||||
[parts.query, restUrl] = takePattern(restUrl, /^(\?[^#]*)/);
|
[parts.query, restUrl] = takePattern(restUrl, /^(\?[^#]*)/);
|
||||||
parts.query = encodeSearch(parts.query);
|
parts.query = encodeSearch(parts.query, isSpecial);
|
||||||
usedNonBase = true;
|
usedNonBase = true;
|
||||||
} else {
|
} else {
|
||||||
parts.query = baseParts.query;
|
parts.query = baseParts.query;
|
||||||
|
@ -660,7 +660,8 @@
|
||||||
set search(value) {
|
set search(value) {
|
||||||
value = String(value);
|
value = String(value);
|
||||||
const query = value == "" || value.charAt(0) == "?" ? value : `?${value}`;
|
const query = value == "" || value.charAt(0) == "?" ? value : `?${value}`;
|
||||||
parts.get(this).query = encodeSearch(query);
|
const isSpecial = specialSchemes.includes(parts.get(this).protocol);
|
||||||
|
parts.get(this).query = encodeSearch(query, isSpecial);
|
||||||
this.#updateSearchParams();
|
this.#updateSearchParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,9 +767,9 @@
|
||||||
return (c >= "\u0000" && c <= "\u001F") || c > "\u007E";
|
return (c >= "\u0000" && c <= "\u001F") || c > "\u007E";
|
||||||
}
|
}
|
||||||
|
|
||||||
function charInSearchSet(c) {
|
function charInSearchSet(c, isSpecial) {
|
||||||
// deno-fmt-ignore
|
// deno-fmt-ignore
|
||||||
return charInC0ControlSet(c) || ["\u0020", "\u0022", "\u0023", "\u0027", "\u003C", "\u003E"].includes(c) || c > "\u007E";
|
return charInC0ControlSet(c) || ["\u0020", "\u0022", "\u0023", "\u003C", "\u003E"].includes(c) || isSpecial && c == "\u0027" || c > "\u007E";
|
||||||
}
|
}
|
||||||
|
|
||||||
function charInFragmentSet(c) {
|
function charInFragmentSet(c) {
|
||||||
|
@ -871,8 +872,10 @@
|
||||||
return [...s].map((c) => (charInPathSet(c) ? encodeChar(c) : c)).join("");
|
return [...s].map((c) => (charInPathSet(c) ? encodeChar(c) : c)).join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function encodeSearch(s) {
|
function encodeSearch(s, isSpecial) {
|
||||||
return [...s].map((c) => (charInSearchSet(c) ? encodeChar(c) : c)).join("");
|
return [...s].map((
|
||||||
|
c,
|
||||||
|
) => (charInSearchSet(c, isSpecial) ? encodeChar(c) : c)).join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function encodeHash(s) {
|
function encodeHash(s) {
|
||||||
|
|
|
@ -272,26 +272,30 @@ unitTest(function urlTrim() {
|
||||||
|
|
||||||
unitTest(function urlEncoding() {
|
unitTest(function urlEncoding() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
new URL("https://a !$&*()=,;+'\"@example.com").username,
|
new URL("http://a !$&*()=,;+'\"@example.com").username,
|
||||||
"a%20!$&*()%3D,%3B+%27%22",
|
"a%20!$&*()%3D,%3B+%27%22",
|
||||||
);
|
);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
new URL("https://:a !$&*()=,;+'\"@example.com").password,
|
new URL("http://:a !$&*()=,;+'\"@example.com").password,
|
||||||
"a%20!$&*()%3D,%3B+%27%22",
|
"a%20!$&*()%3D,%3B+%27%22",
|
||||||
);
|
);
|
||||||
assertEquals(new URL("abcde://mañana/c?d#e").hostname, "ma%C3%B1ana");
|
|
||||||
// https://url.spec.whatwg.org/#idna
|
// https://url.spec.whatwg.org/#idna
|
||||||
assertEquals(new URL("https://mañana/c?d#e").hostname, "xn--maana-pta");
|
assertEquals(new URL("http://mañana/c?d#e").hostname, "xn--maana-pta");
|
||||||
|
assertEquals(new URL("abcd://mañana/c?d#e").hostname, "ma%C3%B1ana");
|
||||||
assertEquals(
|
assertEquals(
|
||||||
new URL("https://example.com/a ~!@$&*()=:/,;+'\"\\").pathname,
|
new URL("http://example.com/a ~!@$&*()=:/,;+'\"\\").pathname,
|
||||||
"/a%20~!@$&*()=:/,;+'%22/",
|
"/a%20~!@$&*()=:/,;+'%22/",
|
||||||
);
|
);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
new URL("https://example.com?a ~!@$&*()=:/,;?+'\"\\").search,
|
new URL("http://example.com?a ~!@$&*()=:/,;?+'\"\\").search,
|
||||||
"?a%20~!@$&*()=:/,;?+%27%22\\",
|
"?a%20~!@$&*()=:/,;?+%27%22\\",
|
||||||
);
|
);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
new URL("https://example.com#a ~!@#$&*()=:/,;?+'\"\\").hash,
|
new URL("abcd://example.com?a ~!@$&*()=:/,;?+'\"\\").search,
|
||||||
|
"?a%20~!@$&*()=:/,;?+'%22\\",
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
new URL("http://example.com#a ~!@#$&*()=:/,;?+'\"\\").hash,
|
||||||
"#a%20~!@#$&*()=:/,;?+'%22\\",
|
"#a%20~!@#$&*()=:/,;?+'%22\\",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue