diff --git a/mozilla/modules/libjar/nsJARURI.cpp b/mozilla/modules/libjar/nsJARURI.cpp index f4aa388f0fa..877dad58381 100644 --- a/mozilla/modules/libjar/nsJARURI.cpp +++ b/mozilla/modules/libjar/nsJARURI.cpp @@ -335,12 +335,27 @@ nsJARURI::Resolve(const nsACString &relativePath, nsACString &result) } nsCAutoString path(mJAREntry); - PRInt32 pos = path.RFind("/"); - if (pos >= 0) - path.Truncate(pos + 1); - else - path = ""; + PRInt32 pos = 0; + char first = relativePath.Length() > 0 ? relativePath.First() : '#'; + + switch (first) { + case '/': + path = ""; + break; + case '?': + case '#': + pos = path.RFindChar(first); + if (pos >= 0) + path.Truncate(pos); + break; + default: + pos = path.RFindChar('/'); + if (pos >= 0) + path.Truncate(pos + 1); + else + path = ""; + } nsCAutoString resolvedEntry; rv = net_ResolveRelativePath(relativePath, path, resolvedEntry); diff --git a/mozilla/netwerk/base/src/nsURLHelper.cpp b/mozilla/netwerk/base/src/nsURLHelper.cpp index c0a2550795f..9a9bcb654d2 100644 --- a/mozilla/netwerk/base/src/nsURLHelper.cpp +++ b/mozilla/netwerk/base/src/nsURLHelper.cpp @@ -383,7 +383,7 @@ net_ResolveRelativePath(const nsACString &relativePath, if ( !path.IsEmpty() ) { PRUnichar last = path.Last(); - needsDelim = !(last == '/' || last == '\\' ); + needsDelim = !(last == '/'); } nsACString::const_iterator beg, end; @@ -403,18 +403,20 @@ net_ResolveRelativePath(const nsACString &relativePath, stop = PR_TRUE; // fall through... case '/': - case '\\': // delimiter found if (name.Equals("..")) { // pop path // If we already have the delim at end, then // skip over that when searching for next one to the left PRInt32 offset = path.Length() - (needsDelim ? 1 : 2); + // First check for errors + if (offset < 0 ) + return NS_ERROR_MALFORMED_URI; PRInt32 pos = path.RFind("/", PR_FALSE, offset); - if (pos > 0) + if (pos >= 0) path.Truncate(pos + 1); else - return NS_ERROR_MALFORMED_URI; + path.Truncate(); } else if (name.Equals(".") || name.Equals("")) { // do nothing diff --git a/mozilla/netwerk/protocol/jar/src/nsJARURI.cpp b/mozilla/netwerk/protocol/jar/src/nsJARURI.cpp index f4aa388f0fa..877dad58381 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARURI.cpp +++ b/mozilla/netwerk/protocol/jar/src/nsJARURI.cpp @@ -335,12 +335,27 @@ nsJARURI::Resolve(const nsACString &relativePath, nsACString &result) } nsCAutoString path(mJAREntry); - PRInt32 pos = path.RFind("/"); - if (pos >= 0) - path.Truncate(pos + 1); - else - path = ""; + PRInt32 pos = 0; + char first = relativePath.Length() > 0 ? relativePath.First() : '#'; + + switch (first) { + case '/': + path = ""; + break; + case '?': + case '#': + pos = path.RFindChar(first); + if (pos >= 0) + path.Truncate(pos); + break; + default: + pos = path.RFindChar('/'); + if (pos >= 0) + path.Truncate(pos + 1); + else + path = ""; + } nsCAutoString resolvedEntry; rv = net_ResolveRelativePath(relativePath, path, resolvedEntry);