Bug 1883033 - Fix Scheme ws/wss/ssh url query-encoding wpt failures r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D225007
This commit is contained in:
Sean 2024-10-10 13:36:13 +00:00
parent c49e6ea04e
commit 80d65c74e8
5 changed files with 54 additions and 12 deletions

View File

@ -1864,6 +1864,14 @@ nsresult NS_NewURI(nsIURI** aURI, const nsACString& aSpec,
if (NS_FAILED(rv)) return rv;
}
// If encoding is not UTF-8 and url is not special or urls scheme is "ws" or
// "wss" then set encoding to UTF-8.
if (aCharset && !scheme.IsEmpty() &&
(scheme.EqualsLiteral("ws") || scheme.EqualsLiteral("wss") ||
!SchemeIsSpecial(scheme))) {
aCharset = "UTF-8";
}
if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("ws")) {
return NewStandardURI(aSpec, aCharset, aBaseURI, NS_HTTP_DEFAULT_PORT,
aURI);

View File

@ -99,6 +99,8 @@ support-files = [
["test_accept_header.html"]
support-files = ["test_accept_header.sjs"]
["test_anchor_query_encoding.html"]
["test_arraybufferinputstream.html"]
["test_arraybufferinputstream_large.html"]

View File

@ -0,0 +1,44 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="windows-1251">
<title>Testing &#x3C;a&#x3E;.href (windows-1251)</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript">
const UTF_8 = '%C3%A5';
const WINDOWS_1251 = '%26%23229%3B';
function test_scheme(url, expected) {
var a = document.createElement('a');
a.setAttribute('href', url);
ok(a.href.includes(expected), `Expected: ${expected}, Actual: ${a.href}`);
}
add_task(async function test_bug1883033() {
// Scheme http (getting <a>.href)
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
test_scheme("http://example.invalid/?x=\u00E5", WINDOWS_1251);
// Scheme https (getting <a>.href)
test_scheme("https://example.invalid/?x=\u00E5", WINDOWS_1251);
// If encoding is not UTF-8 and urls scheme is "ws" or "wss",
// then encoding should be set to UTF-8.
// Scheme ws (getting <a>.href)
test_scheme("ws://example.invalid/?x=\u00E5", UTF_8);
// Scheme wss (getting <a>.href)
test_scheme("wss://example.invalid/?x=\u00E5", UTF_8);
// If encoding is not UTF-8 and url is not special,
// then encoding should be UTF-8.
// Scheme ssh (getting <a>.href)
test_scheme("ssh://foo/?x=\u00E5", UTF_8);
});
</script>
</head>
<body>
</body>
</html>

View File

@ -280,12 +280,6 @@
[windows-1251.html?include=scheme]
[Scheme ws (getting <a>.href)]
expected: FAIL
[Scheme wss (getting <a>.href)]
expected: FAIL
[windows-1251.html?include=appcache]
[Parsing cache manifest (CACHE)]

View File

@ -82,12 +82,6 @@
[windows-1252.html?include=submit]
[windows-1252.html?include=scheme]
[Scheme ws (getting <a>.href)]
expected: FAIL
[Scheme wss (getting <a>.href)]
expected: FAIL
[windows-1252.html?include=eventsource]