Bug 1488061 - Remove Query/Ref from the directory listing URI r=bagder
authorValentin Gosu <valentin.gosu@gmail.com>
Tue, 11 Sep 2018 14:33:34 +0300
changeset 435667 e414fcdabb7209d3ac6a0052f4c0c8c8c89ab35d
parent 435666 5d653605ce14ca4afe2b5c81b6dd7d304fd087dc
child 435668 8c80d535191663a92bd28e5759a557871bf62962
push id107700
push userarchaeopteryx@coole-files.de
push dateTue, 11 Sep 2018 11:36:45 +0000
treeherdermozilla-inbound@e414fcdabb72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1488061
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1488061 - Remove Query/Ref from the directory listing URI r=bagder
netwerk/streamconv/converters/nsIndexedToHTML.cpp
--- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp
+++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp
@@ -159,17 +159,25 @@ nsIndexedToHTML::DoOnStartRequest(nsIReq
     if (NS_FAILED(rv)) return rv;
 
     rv = mParser->OnStartRequest(request, aContext);
     if (NS_FAILED(rv)) return rv;
 
     nsAutoCString baseUri, titleUri;
     rv = uri->GetAsciiSpec(baseUri);
     if (NS_FAILED(rv)) return rv;
-    titleUri = baseUri;
+
+    nsCOMPtr<nsIURI> titleURL;
+    rv = NS_MutateURI(uri)
+           .SetQuery(EmptyCString())
+           .SetRef(EmptyCString())
+           .Finalize(titleURL);
+    if (NS_FAILED(rv)) {
+        titleURL = uri;
+    }
 
     nsCString parentStr;
 
     nsCString buffer;
     buffer.AppendLiteral("<!DOCTYPE html>\n<html>\n<head>\n");
 
     // XXX - should be using the 300: line from the parser.
     // We can't guarantee that that comes before any entry, so we'd have to
@@ -183,25 +191,23 @@ nsIndexedToHTML::DoOnStartRequest(nsIReq
     bool isSchemeFile = false;
     if (NS_SUCCEEDED(uri->SchemeIs("ftp", &isScheme)) && isScheme) {
 
         // 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
 
         nsAutoCString pw;
-        rv = uri->GetPassword(pw);
+        rv = titleURL->GetPassword(pw);
         if (NS_FAILED(rv)) return rv;
         if (!pw.IsEmpty()) {
              nsCOMPtr<nsIURI> newUri;
-             rv = NS_MutateURI(uri)
+             rv = NS_MutateURI(titleURL)
                     .SetPassword(EmptyCString())
-                    .Finalize(newUri);
-             if (NS_FAILED(rv)) return rv;
-             rv = newUri->GetAsciiSpec(titleUri);
+                    .Finalize(titleURL);
              if (NS_FAILED(rv)) return rv;
         }
 
         nsAutoCString path;
         rv = uri->GetPathQueryRef(path);
         if (NS_FAILED(rv)) return rv;
 
         if (!path.EqualsLiteral("//") && !path.LowerCaseEqualsLiteral("/%2f")) {
@@ -262,16 +268,21 @@ nsIndexedToHTML::DoOnStartRequest(nsIReq
                                  .Finalize(uri);
         }
         if (!path.EqualsLiteral("/")) {
             rv = uri->Resolve(NS_LITERAL_CSTRING(".."), parentStr);
             if (NS_FAILED(rv)) return rv;
         }
     }
 
+    rv = titleURL->GetAsciiSpec(titleUri);
+    if (NS_FAILED(rv)) {
+        return rv;
+    }
+
     buffer.AppendLiteral("<style type=\"text/css\">\n"
                          ":root {\n"
                          "  font-family: sans-serif;\n"
                          "}\n"
                          "img {\n"
                          "  border: 0;\n"
                          "}\n"
                          "th {\n"