Skip to content

Instantly share code, notes, and snippets.

@Infocatcher
Created November 7, 2018 14:11
Show Gist options
  • Save Infocatcher/6c1bb9f9550fc935c8a5c86b645d3996 to your computer and use it in GitHub Desktop.
Save Infocatcher/6c1bb9f9550fc935c8a5c86b645d3996 to your computer and use it in GitHub Desktop.
var uris = {
"http://example.com/": true,
"https://example.com/": true,
"https://example.com/foo/bar.php?key=val&key2=val2#hash": true,
"file:///": true,
"ftp://example.com": true,
//"about:": true, // Removed in new versions
"about:newtab": true,
"about:config": true,
"about:cache?device=memory": true,
"chrome://browser/content/browser.js": true,
"resource:///modules/DownloadsCommon.jsm": true,
"http://": false,
//"ftp://": false,
"http://?example.com/": false,
"http://#example.com/": false,
"http99://a/": false,
"unknown://": false,
"chrome://browser/": false,
"about:something-not-registered": false,
"not a URI": false,
"not-a-URI": false
};
function isValidURI(spec) {
try {
Services.io.newURI(spec, null, null); // Forbid relative URIs
var req = new XMLHttpRequest();
req.open("head", spec, true); // Simple way to try create nsIChannel instance
return !!req.channel;
}
catch(e) {
//Components.utils.reportError(e);
}
return false;
}
var failed = [];
for(var spec in uris)
if(isValidURI(spec) != uris[spec])
failed.push(spec);
alert(failed.length ? "Test failed for\n" + failed.join("\n") : "OK!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment