Bug 430910 - nsStandardURL gets confused when the query string or the anchor name contains slash characters; r=bzbarsky a=roc

This commit is contained in:
Ehsan Akhgari 2010-09-24 14:21:17 -04:00
parent d678ca7e0d
commit c15794aaf5
2 changed files with 21 additions and 3 deletions

View File

@ -2005,13 +2005,13 @@ nsStandardURL::GetRelativeSpec(nsIURI *uri2, nsACString &aResult)
while ((*(thatIndex-1) != '/') && (thatIndex != startCharPos))
thatIndex--;
const char *limit = mSpec.get() + mFilepath.mPos + mFilepath.mLen;
// need to account for slashes and add corresponding "../"
while (*thisIndex)
for (; thisIndex <= limit && *thisIndex; ++thisIndex)
{
if (*thisIndex == '/')
aResult.AppendLiteral("../");
thisIndex++;
}
// grab spec from thisIndex to end

View File

@ -17,6 +17,24 @@ function run_test() {
["http://foo.com/bar/", "http://foo.com:80/bar/", "" ],
["http://foo.com/", "http://foo.com/a.htm#b", "a.htm#b" ],
["http://foo.com/a/b/", "http://foo.com/c", "../../c" ],
["http://foo.com/a?b/c/", "http://foo.com/c" , "c" ],
["http://foo.com/a#b/c/", "http://foo.com/c" , "c" ],
["http://foo.com/a;p?b/c/", "http://foo.com/c" , "c" ],
["http://foo.com/a/b?c/d/", "http://foo.com/c", "../c" ],
["http://foo.com/a/b#c/d/", "http://foo.com/c", "../c" ],
["http://foo.com/a/b;p?c/d/", "http://foo.com/c", "../c" ],
["http://foo.com/a/b/c?d/e/", "http://foo.com/f", "../../f" ],
["http://foo.com/a/b/c#d/e/", "http://foo.com/f", "../../f" ],
["http://foo.com/a/b/c;p?d/e/", "http://foo.com/f", "../../f" ],
["http://foo.com/a?b/c/", "http://foo.com/c/d" , "c/d" ],
["http://foo.com/a#b/c/", "http://foo.com/c/d" , "c/d" ],
["http://foo.com/a;p?b/c/", "http://foo.com/c/d" , "c/d" ],
["http://foo.com/a/b?c/d/", "http://foo.com/c/d", "../c/d" ],
["http://foo.com/a/b#c/d/", "http://foo.com/c/d", "../c/d" ],
["http://foo.com/a/b;p?c/d/", "http://foo.com/c/d", "../c/d" ],
["http://foo.com/a/b/c?d/e/", "http://foo.com/f/g/", "../../f/g/" ],
["http://foo.com/a/b/c#d/e/", "http://foo.com/f/g/", "../../f/g/" ],
["http://foo.com/a/b/c;p?d/e/", "http://foo.com/f/g/", "../../f/g/" ],
];
for (var i = 0; i < tests.length; i++) {