From babca5a336a6ff39e17f0c8fa8f4bfcb5b28148c Mon Sep 17 00:00:00 2001 From: "reed@reedloden.com" Date: Mon, 5 Nov 2007 13:02:52 -0800 Subject: [PATCH] Bug 391855 - "FTP directory URL without a trailing slash can result in files being uploaded to the wrong place" [p=wgianopoulos@yahoo.com (Bill Gianopoulos) r=dougt sr=biesi aM9=beltzner] --- .../protocol/ftp/src/nsFtpConnectionThread.cpp | 14 ++++++++++++++ .../streamconv/converters/nsIndexedToHTML.cpp | 18 ++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp index cb7a43e239e..14a58db48af 100644 --- a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp +++ b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp @@ -1044,6 +1044,20 @@ nsFtpState::R_mdtm() { nsresult nsFtpState::SetContentType() { + // FTP directory URLs don't always end in a slash. Make sure they do. + // This check needs to be here rather than a more obvious place + // (e.g. LIST command processing) so that it ensures the terminating + // slash is appended for the new request case, as well as the case + // where the URL is being loaded from the cache. + + if (!mPath.IsEmpty() && mPath.Last() != '/') { + nsCOMPtr url = (do_QueryInterface(mChannel->URI())); + nsCAutoString filePath; + if(NS_SUCCEEDED(url->GetFilePath(filePath))) { + filePath.Append('/'); + url->SetFilePath(filePath); + } + } return mChannel->SetContentType( NS_LITERAL_CSTRING(APPLICATION_HTTP_INDEX_FORMAT)); } diff --git a/netwerk/streamconv/converters/nsIndexedToHTML.cpp b/netwerk/streamconv/converters/nsIndexedToHTML.cpp index 3e621986633..a93e84c68af 100644 --- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp +++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp @@ -166,18 +166,6 @@ nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) { PRBool isSchemeGopher = PR_FALSE; if (NS_SUCCEEDED(uri->SchemeIs("ftp", &isScheme)) && isScheme) { - // ftp urls don't always end in a / - // make sure they do - // but look out for /%2F as path - nsCAutoString path; - rv = uri->GetPath(path); - if (NS_FAILED(rv)) return rv; - if (baseUri.Last() != '/' && !path.LowerCaseEqualsLiteral("/%2f")) { - baseUri.Append('/'); - path.Append('/'); - uri->SetPath(path); - } - // strip out the password here, so it doesn't show in the page title // This is done by the 300: line generation in ftp, but we don't use // that - see above @@ -193,10 +181,12 @@ nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) { if (NS_FAILED(rv)) return rv; rv = newUri->GetAsciiSpec(titleUri); if (NS_FAILED(rv)) return rv; - if (titleUri.Last() != '/' && !path.LowerCaseEqualsLiteral("/%2f")) - titleUri.Append('/'); } + nsCAutoString path; + rv = uri->GetPath(path); + if (NS_FAILED(rv)) return rv; + if (!path.EqualsLiteral("//") && !path.LowerCaseEqualsLiteral("/%2f")) { rv = uri->Resolve(NS_LITERAL_CSTRING(".."),parentStr); if (NS_FAILED(rv)) return rv;