From 7a2900ad0cd52e9c5692b53fbdb41e91806219ce Mon Sep 17 00:00:00 2001 From: "andreas.otte%debitel.net" Date: Sat, 15 Mar 2003 20:00:20 +0000 Subject: [PATCH] fix bug 113032 [jar: anchors within pages drop the HTML file name] fix resolving relative jar urls, fix anchor handling in jar urls, r=darin, sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@139530 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/libjar/nsJARURI.cpp | 25 +++++++++++++++---- mozilla/netwerk/base/src/nsURLHelper.cpp | 10 +++++--- mozilla/netwerk/protocol/jar/src/nsJARURI.cpp | 25 +++++++++++++++---- 3 files changed, 46 insertions(+), 14 deletions(-) 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);