Bug 1384168 - Handle invalid aURI in _isLocalAboutURI. r=Mardak

MozReview-Commit-ID: FxZjLTZKISw

--HG--
extra : rebase_source : 37dee526b4209ff4f74e9f89d7e3e041a6094710
This commit is contained in:
Samael Wang 2017-07-28 18:47:35 +08:00
Родитель ca42c67654
Коммит f690118f45
2 изменённых файлов: 22 добавлений и 11 удалений

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

@ -530,16 +530,21 @@
return true;
}
// Use the passed in resolvedURI if we have one
const resolvedURI = aResolvedURI || Services.io.newChannelFromURI2(
aURI,
null, // loadingNode
Services.scriptSecurityManager.getSystemPrincipal(), // loadingPrincipal
null, // triggeringPrincipal
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, // securityFlags
Ci.nsIContentPolicy.TYPE_OTHER // contentPolicyType
).URI;
return resolvedURI.schemeIs("jar") || resolvedURI.schemeIs("file");
try {
// Use the passed in resolvedURI if we have one
const resolvedURI = aResolvedURI || Services.io.newChannelFromURI2(
aURI,
null, // loadingNode
Services.scriptSecurityManager.getSystemPrincipal(), // loadingPrincipal
null, // triggeringPrincipal
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, // securityFlags
Ci.nsIContentPolicy.TYPE_OTHER // contentPolicyType
).URI;
return resolvedURI.schemeIs("jar") || resolvedURI.schemeIs("file");
} catch (ex) {
// aURI might be invalid.
return false;
}
]]></body>
</method>

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

@ -11,13 +11,19 @@
add_task(function test_URI() {
const check = (spec, expect, description) => {
const URI = Services.io.newURI(spec);
is(gBrowser._isLocalAboutURI(URI), expect, description);
try {
is(gBrowser._isLocalAboutURI(URI), expect, description);
} catch (ex) {
ok(false, "_isLocalAboutURI should not throw");
}
};
check("https://www.mozilla.org/", false, "https is not about");
check("http://www.mozilla.org/", false, "http is not about");
check("about:blank", true, "about:blank is local");
check("about:about", true, "about:about is local");
check("about:newtab", true, "about:newtab is local");
check("about:random-invalid-uri", false,
"about:random-invalid-uri is invalid but should not throw");
});
add_task(function test_URI_with_resolved() {