mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-20 23:37:33 +09:00
fix ws, wss and moz-extension in matchpattern
This commit is contained in:
parent
639d4eb85f
commit
5eb353096b
3 changed files with 33 additions and 2 deletions
|
|
@ -0,0 +1,26 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
add_task(function* test_explicit_webextension_schemes() {
|
||||||
|
let {MatchPattern} = Cu.import("resource://gre/modules/MatchPattern.jsm", {});
|
||||||
|
let patterns = [
|
||||||
|
["moz-extension://6e20d047-ef47-41c0-a95f-93aa35f1798d/web_accessible_resources/*",
|
||||||
|
"moz-extension://6e20d047-ef47-41c0-a95f-93aa35f1798d/web_accessible_resources/file.js"],
|
||||||
|
["ws://*/*", "ws://example.com/socket"],
|
||||||
|
["wss://*/*", "wss://example.com/socket"],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let [pattern, url] of patterns) {
|
||||||
|
let matcher = new MatchPattern(pattern);
|
||||||
|
ok(matcher.matches(Services.io.newURI(url, null, null)),
|
||||||
|
`explicit scheme is accepted: ${pattern}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* test_wildcard_remains_web_only() {
|
||||||
|
let {MatchPattern} = Cu.import("resource://gre/modules/MatchPattern.jsm", {});
|
||||||
|
let matcher = new MatchPattern("*://*/*");
|
||||||
|
ok(!matcher.matches(Services.io.newURI("ws://example.com/socket", null, null)),
|
||||||
|
"scheme wildcard does not implicitly include WebSockets");
|
||||||
|
ok(!matcher.matches(Services.io.newURI("moz-extension://example/", null, null)),
|
||||||
|
"scheme wildcard does not include extension URLs");
|
||||||
|
});
|
||||||
|
|
@ -9,6 +9,7 @@ tags = webextensions
|
||||||
|
|
||||||
[test_csp_custom_policies.js]
|
[test_csp_custom_policies.js]
|
||||||
[test_webrequest_backend.js]
|
[test_webrequest_backend.js]
|
||||||
|
[test_match_pattern_schemes.js]
|
||||||
[test_webnavigation_created_target.js]
|
[test_webnavigation_created_target.js]
|
||||||
[test_csp_validator.js]
|
[test_csp_validator.js]
|
||||||
[test_ext_alarms.js]
|
[test_ext_alarms.js]
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,11 @@ this.EXPORTED_SYMBOLS = ["MatchPattern", "MatchGlobs", "MatchURLFilters"];
|
||||||
|
|
||||||
/* globals MatchPattern, MatchGlobs */
|
/* globals MatchPattern, MatchGlobs */
|
||||||
|
|
||||||
const PERMITTED_SCHEMES = ["http", "https", "file", "ftp", "data"];
|
// Keep explicit scheme support broad enough for WebExtensions, while the
|
||||||
|
// match-pattern wildcard remains restricted to web content schemes below.
|
||||||
|
const PERMITTED_SCHEMES = ["http", "https", "file", "ftp", "data",
|
||||||
|
"ws", "wss", "moz-extension"];
|
||||||
|
const ALL_URLS_SCHEMES = ["http", "https", "file", "ftp", "data", "ws", "wss"];
|
||||||
const PERMITTED_SCHEMES_REGEXP = PERMITTED_SCHEMES.join("|");
|
const PERMITTED_SCHEMES_REGEXP = PERMITTED_SCHEMES.join("|");
|
||||||
|
|
||||||
// This function converts a glob pattern (containing * and possibly ?
|
// This function converts a glob pattern (containing * and possibly ?
|
||||||
|
|
@ -40,7 +44,7 @@ function globToRegexp(pat, allowQuestion) {
|
||||||
// https://developer.chrome.com/extensions/match_patterns
|
// https://developer.chrome.com/extensions/match_patterns
|
||||||
function SingleMatchPattern(pat) {
|
function SingleMatchPattern(pat) {
|
||||||
if (pat == "<all_urls>") {
|
if (pat == "<all_urls>") {
|
||||||
this.schemes = PERMITTED_SCHEMES;
|
this.schemes = ALL_URLS_SCHEMES;
|
||||||
this.hostMatch = () => true;
|
this.hostMatch = () => true;
|
||||||
this.pathMatch = () => true;
|
this.pathMatch = () => true;
|
||||||
} else if (!pat) {
|
} else if (!pat) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue