Bug 1429590 - Only allow one homepage to be set by extensions r=aswan

MozReview-Commit-ID: 8DTj8ceWAr8

--HG--
extra : rebase_source : 006f967cfd183e9c915e622056fec10ab173842e
This commit is contained in:
Mark Striemer 2018-01-31 20:21:32 -06:00
Родитель 5b70ea834b
Коммит 5431ec74a5
3 изменённых файлов: 30 добавлений и 1 удалений

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

@ -12,7 +12,7 @@
"properties": {
"homepage": {
"type": "string",
"format": "relativeUrl",
"format": "homepageUrl",
"optional": true,
"preprocess": "localize"
},

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

@ -269,3 +269,24 @@ add_task(async function test_local() {
await ext1.unload();
});
add_task(async function test_multiple() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
chrome_settings_overrides: {
homepage: "https://mozilla.org/|https://developer.mozilla.org/|https://addons.mozilla.org/",
},
},
useAddonManager: "temporary",
});
let prefPromise = promisePrefChangeObserved(HOMEPAGE_URL_PREF);
await extension.startup();
await prefPromise;
is(getHomePageURL(),
"https://mozilla.org/%7Chttps://developer.mozilla.org/%7Chttps://addons.mozilla.org/",
"The homepage encodes | so only one homepage is allowed");
await extension.unload();
});

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

@ -936,6 +936,14 @@ const FORMATS = {
throw new SyntaxError(`String ${JSON.stringify(string)} must be a relative URL`);
},
homepageUrl(string, context) {
// Pipes are used for separating homepages, but we only allow extensions to
// set a single homepage. Encoding any pipes makes it one URL.
return FORMATS.relativeUrl(
string.replace(new RegExp("\\|", "g"), "%7C"),
context);
},
imageDataOrStrictRelativeUrl(string, context) {
// Do not accept a string which resolves as an absolute URL, or any
// protocol-relative URL, except PNG or JPG data URLs