RequestPolicy/tractest — Issue #238: DomainUtil.parseRefresh() does not accommodate all variations accepted by Firefox
Author: jsamuel
Created: 2011-12-22 02:48:45+00:00
State: open
Labels: extension

The {{{DomainUtil.parseRefresh()}}} function is defined as follows:
{{{
/**
* Gets the relevant pieces out of a meta refresh or header refresh string.
*
* @param {String}
* refreshString The original content of a refresh header or meta tag.
* @return {Array} First element is the delay in seconds, second element is the
* url to refresh to. The url may be an empty string if the current url
* should be refreshed.
* @throws Generic
* exception if the refreshString has an invalid format, including if
* the seconds can't be parsed as a float.
*/
DomainUtil.parseRefresh = function(refreshString) {
var parts = /^\s*(\S*?)\s*(;\s*url\s*=\s*(.*?)\s*)?$/i(refreshString);
var delay = parseFloat(parts[1]);
if (isNaN(delay)) {
throw "Invalid delay value in refresh string: " + parts[1];
}
var url = parts[3];
if (url == undefined) {
url = '';
}
// Strip off enclosing quotes around the url.
if (url) {
var first = url[0];
var last = url[url.length - 1];
if (first == last && (first == "'" || first == '"')) {
url = url.substring(1, url.length - 1);
}
}
return [delay, url];
}
}}}
However, this does not properly parse all strings accepted by Firefox. For example, {{{parseRefresh("0;b.html")}}} correctly sets the delay from {{{parseFloat("0;b.html")}}}; however, the {{{url}}} is incorrectly presumed {{{undefined}}}...