Bug 397937 - Handle view-source on malware and error pages more gracefully, r=mconnor
This commit is contained in:
@@ -78,23 +78,32 @@
|
||||
function getURL()
|
||||
{
|
||||
var url = document.documentURI;
|
||||
var index = url.search(/u\=/);
|
||||
var match = url.match(/&u=([^&]+)&/);
|
||||
|
||||
// index == -1 if not found; if so, return an empty string
|
||||
// match == null if not found; if so, return an empty string
|
||||
// instead of what would turn out to be portions of the URI
|
||||
if (index == -1)
|
||||
if (!match)
|
||||
return "";
|
||||
|
||||
return decodeURIComponent(url.slice(index + 2));
|
||||
url = decodeURIComponent(match[1]);
|
||||
|
||||
// If this is a view-source page, then get then real URI of the page
|
||||
if (/^view-source\:/.test(url))
|
||||
url = url.slice(12);
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to parse the result of getURL and extract a hostname. Fail back
|
||||
* Attempt to get the hostname via document.location. Fail back
|
||||
* to getURL so that we always return something meaningful.
|
||||
*/
|
||||
function getHostString()
|
||||
{
|
||||
return document.location.hostname;
|
||||
try {
|
||||
return document.location.hostname;
|
||||
} catch (e) {
|
||||
return getURL();
|
||||
}
|
||||
}
|
||||
|
||||
function initPage()
|
||||
|
||||
Reference in New Issue
Block a user