Bug 1877753 - Disable DefaultURI for unknown schemes. r=valentin,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D200193
This commit is contained in:
Ed 2024-02-02 09:41:36 +00:00
Родитель 2638164bac
Коммит bc744d5bed
6 изменённых файлов: 50 добавлений и 35 удалений

Просмотреть файл

@ -448,44 +448,54 @@
</script>
<script>
var url = new URL("scheme:path/to/file?query#hash");
is(url.href, "scheme:path/to/file?query#hash");
is(url.pathname, "path/to/file");
is(url.search, "?query");
is(url.hash, "#hash");
async function testStrippingAndEncoding() {
await SpecialPowers.pushPrefEnv({ set: [
["network.url.useDefaultURI", true],
]});
// pathname cannot be overwritten.
url.pathname = "new/path?newquery#newhash";
is(url.href, "scheme:path/to/file?query#hash");
var url = new URL("scheme:path/to/file?query#hash");
is(url.href, "scheme:path/to/file?query#hash");
is(url.pathname, "path/to/file");
is(url.search, "?query");
is(url.hash, "#hash");
// don't escape '#' until we implement a spec-compliant parser.
url.search = "?newquery#newhash";
is(url.href, "scheme:path/to/file?newquery%23newhash#hash");
// pathname cannot be overwritten.
url.pathname = "new/path?newquery#newhash";
is(url.href, "scheme:path/to/file?query#hash");
// nulls get encoded, whitespace gets stripped
url = new URL("scheme:pa\0\nth/to/fi\0\nle?qu\0\nery#ha\0\nsh");
is(url.href, "scheme:pa%00th/to/fi%00le?qu%00ery#ha%00sh");
// don't escape '#' until we implement a spec-compliant parser.
url.search = "?newquery#newhash";
is(url.href, "scheme:path/to/file?newquery%23newhash#hash");
url.search = "new\0\nquery";
is(url.href, "scheme:pa%00th/to/fi%00le?new%00query#ha%00sh");
url.hash = "new\0\nhash";
is(url.href, "scheme:pa%00th/to/fi%00le?new%00query#new%00hash");
// nulls get encoded, whitespace gets stripped
url = new URL("scheme:pa\0\nth/to/fi\0\nle?qu\0\nery#ha\0\nsh");
is(url.href, "scheme:pa%00th/to/fi%00le?qu%00ery#ha%00sh");
url = new URL("scheme:path#hash");
is(url.href, "scheme:path#hash");
url.search = "query";
is(url.href, "scheme:path?query#hash");
url.hash = "";
is(url.href, "scheme:path?query");
url.hash = "newhash";
is(url.href, "scheme:path?query#newhash");
url.search = "";
is(url.href, "scheme:path#newhash");
url.search = "new\0\nquery";
is(url.href, "scheme:pa%00th/to/fi%00le?new%00query#ha%00sh");
url.hash = "new\0\nhash";
is(url.href, "scheme:pa%00th/to/fi%00le?new%00query#new%00hash");
// we don't implement a spec-compliant parser yet.
// make sure we are bug compatible with existing implementations.
url = new URL("data:text/html,<a href=\"http://example.org/?q\">Link</a>");
is(url.href, "data:text/html,<a href=\"http://example.org/?q\">Link</a>");
url = new URL("scheme:path#hash");
is(url.href, "scheme:path#hash");
url.search = "query";
is(url.href, "scheme:path?query#hash");
url.hash = "";
is(url.href, "scheme:path?query");
url.hash = "newhash";
is(url.href, "scheme:path?query#newhash");
url.search = "";
is(url.href, "scheme:path#newhash");
// we don't implement a spec-compliant parser yet.
// make sure we are bug compatible with existing implementations.
url = new URL("data:text/html,<a href=\"http://example.org/?q\">Link</a>");
is(url.href, "data:text/html,<a href=\"http://example.org/?q\">Link</a>");
SimpleTest.finish();
};
SimpleTest.waitForExplicitFinish();
testStrippingAndEncoding();
</script>
<script>

Просмотреть файл

@ -12335,7 +12335,7 @@
# Whether to use the rust implemented DefaultURI for unknown scheme types
- name: network.url.useDefaultURI
type: RelaxedAtomicBool
value: true
value: false
mirror: always
# The maximum allowed length for a URL - 32MB default.

Просмотреть файл

@ -14,6 +14,8 @@
// http://greenbytes.de/tech/webdav/rfc3986.html#rfc.section.5.4
// http://greenbytes.de/tech/tc/uris/
Services.prefs.setBoolPref("network.url.useDefaultURI", true);
// TEST DATA
// ---------
var gTests = [

Просмотреть файл

@ -1,2 +1,4 @@
lsan-allowed: [Alloc, NS_NewRunnableFunction, Realloc, _M_init_functor, mozilla::net::HttpChannelChild::ContinueAsyncOpen, nsHtml5Parser::MarkAsNotScriptCreated]
leak-threshold: [tab:51200]
prefs: [network.url.useDefaultURI:true]

Просмотреть файл

@ -1 +1 @@
prefs: [dom.targetBlankNoOpener.enabled:true]
prefs: [dom.targetBlankNoOpener.enabled:true, network.url.useDefaultURI:true]

Просмотреть файл

@ -1,3 +1,4 @@
leak-threshold: [default:51200, tab:51200]
prefs: [network.dns.native-is-localhost:true,
network.url.strict_protocol_setter:true]
network.url.strict_protocol_setter:true,
network.url.useDefaultURI:true]