1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 00:17:58 +01:00

make sure URLs processed as a result of "gu" don't have //../ (the double

forward slash) at the end
This commit is contained in:
Doug Kearns
2007-08-16 15:49:52 +00:00
parent 39e8df4b03
commit 69fa3f8fff

View File

@@ -1246,11 +1246,16 @@ String.prototype.toURLArray = function() // {{{
begin: for (var url = 0; url < urls.length; url++) begin: for (var url = 0; url < urls.length; url++)
{ {
var newLocation = vimperator.buffer.location;
// FIXME: classic '10 second hack' to fix "gu" foobar//../ problem
newLocation = newLocation.replace(/\/+$/, '');
// FIXME: not really that good (doesn't handle .. in the middle), also problems with trailing slashes // FIXME: not really that good (doesn't handle .. in the middle), also problems with trailing slashes
// check for ./ and ../ (or even .../) to go to a file in the upper directory // check for ./ and ../ (or even .../) to go to a file in the upper directory
if (urls[url].match(/^(\.$|\.\/\S*)/)) if (urls[url].match(/^(\.$|\.\/\S*)/))
{ {
var newLocation = vimperator.buffer.location;
newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1"); newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1");
if (urls[url].match(/^\.(\/\S+)/)) if (urls[url].match(/^\.(\/\S+)/))
newLocation += urls[url].replace(/^\.(\/\S+)/, "$1"); newLocation += urls[url].replace(/^\.(\/\S+)/, "$1");
@@ -1260,7 +1265,6 @@ String.prototype.toURLArray = function() // {{{
} }
else if (urls[url].match(/^(\.\.$|\.\.\/[\S]*)/)) else if (urls[url].match(/^(\.\.$|\.\.\/[\S]*)/))
{ {
var newLocation = vimperator.buffer.location;
newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1/../"); newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1/../");
if (urls[url].match(/^\.\.(\/\S+)/)) if (urls[url].match(/^\.\.(\/\S+)/))
newLocation += urls[url].replace(/^\.\.\/(\S+)/, "$1"); newLocation += urls[url].replace(/^\.\.\/(\S+)/, "$1");
@@ -1270,7 +1274,6 @@ String.prototype.toURLArray = function() // {{{
} }
else if (urls[url].match(/^(\.\.\.$|\.\.\.\/[\S]*)/)) else if (urls[url].match(/^(\.\.\.$|\.\.\.\/[\S]*)/))
{ {
var newLocation = vimperator.buffer.location;
newLocation = newLocation.replace(/([\s\S]+):\/\/\/?(\S+?)\/\S*/, "$1://$2/"); newLocation = newLocation.replace(/([\s\S]+):\/\/\/?(\S+?)\/\S*/, "$1://$2/");
if (urls[url].match(/^\.\.\.(\/\S+)/)) if (urls[url].match(/^\.\.\.(\/\S+)/))
newLocation += urls[url].replace(/^\.\.\.\/(\S+)/, "$1"); newLocation += urls[url].replace(/^\.\.\.\/(\S+)/, "$1");