Bug 1601526: Manifest scope should default to the directory of the resolved start_url. r=marcosc

Differential Revision: https://phabricator.services.mozilla.com/D55903

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dave Townsend 2019-12-05 06:13:10 +00:00
parent 75124bdd98
commit 6379bd94ae
2 changed files with 14 additions and 12 deletions

View File

@ -216,21 +216,22 @@ var ManifestProcessor = {
};
let scopeURL;
const startURL = new URL(processedManifest.start_url);
const defaultScope = new URL(".", startURL).href;
const value = extractor.extractValue(spec);
if (value === undefined || value === "") {
return undefined;
return defaultScope;
}
try {
scopeURL = new URL(value, manifestURL);
} catch (e) {
const warn = domBundle.GetStringFromName("ManifestScopeURLInvalid");
errors.push({ warn });
return undefined;
return defaultScope;
}
if (scopeURL.origin !== docURL.origin) {
const warn = domBundle.GetStringFromName("ManifestScopeNotSameOrigin");
errors.push({ warn });
return undefined;
return defaultScope;
}
// If start URL is not within scope of scope URL:
let isSameOrigin = startURL && startURL.origin !== scopeURL.origin;
@ -239,7 +240,7 @@ var ManifestProcessor = {
"ManifestStartURLOutsideScope"
);
errors.push({ warn });
return undefined;
return defaultScope;
}
return scopeURL.href;
}

View File

@ -17,28 +17,28 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1079453
**/
"use strict";
var expected = "Expect non-string scope to be undefined";
var expected = "Expect non-string scope to be the default";
typeTests.forEach((type) => {
data.jsonText = JSON.stringify({
scope: type,
});
var result = processor.process(data);
is(result.scope, undefined, expected);
is(result.scope, new URL(".", docURL).href, expected);
});
expected = "Expect different origin to be treated as undefined";
expected = "Expect different origin to be the default";
data.jsonText = JSON.stringify({
scope: "http://not-same-origin",
});
var result = processor.process(data);
is(result.scope, undefined, expected);
is(result.scope, new URL(".", docURL).href, expected);
expected = "Expect the empty string to be treated as undefined.";
expected = "Expect the empty string to be the default";
data.jsonText = JSON.stringify({
scope: "",
});
result = processor.process(data);
is(result.scope, undefined, expected);
is(result.scope, new URL(".", docURL).href, expected);
expected = "Resolve URLs relative to manifest.";
var URLs = ["path", "/path", "../../path"];
@ -52,13 +52,14 @@ URLs.forEach((url) => {
is(result.scope, absURL, expected);
});
expected = "If start URL is not in scope, return undefined.";
expected = "If start URL is not in scope, return the default.";
data.jsonText = JSON.stringify({
scope: "foo",
start_url: "bar",
});
result = processor.process(data);
is(result.scope, undefined, expected);
let expected_start = new URL("bar", docURL);
is(result.scope, new URL(document.location.origin).href, expected);
expected = "If start URL is in scope, use the scope.";
data.jsonText = JSON.stringify({