Bug 1415574 - make nsJARURI::SetSpecWithBase ignore URL string; r=bagder
authorLiang-Heng Chen <xeonchen@gmail.com>
Tue, 21 Nov 2017 14:26:43 +0800
changeset 448562 c76ff8b1c4d4ed78fb0d17f60c467d576e0efba2
parent 448561 5f4691a291cf811206ee77d40cc1477f54e2f084
child 448584 c9ce08c45635d29120d5360fb9306125af7bc1ca
child 448589 13faabcf8e965cca857e3cc8fdbea289a09c7ea0
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1415574
milestone59.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 1415574 - make nsJARURI::SetSpecWithBase ignore URL string; r=bagder MozReview-Commit-ID: 9090OAAP7QD
modules/libjar/nsJARURI.cpp
modules/libjar/test/unit/test_bug1328865.js
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -321,38 +321,45 @@ nsJARURI::SetSpecWithBase(const nsACStri
     aSpec.BeginReading(begin);
     aSpec.EndReading(end);
 
     while (begin != end && *begin != ':')
         ++begin;
 
     ++begin; // now we're past the "jar:"
 
+    nsACString::const_iterator delim_begin = begin;
+    nsACString::const_iterator delim_end = end;
     nsACString::const_iterator frag = begin;
-    while (frag != end && *frag != '#') {
+
+    if (FindInReadable(NS_JAR_DELIMITER, delim_begin, delim_end)) {
+        frag = delim_end;
+    }
+    while (frag != end && (*frag != '#' && *frag != '?')) {
         ++frag;
     }
     if (frag != end) {
-        // there was a fragment, mark that as the end of the URL to scan
+        // there was a fragment or query, mark that as the end of the URL to scan
         end = frag;
     }
 
     // Search backward from the end for the "!/" delimiter. Remember, jar URLs
     // can nest, e.g.:
     //    jar:jar:http://www.foo.com/bar.jar!/a.jar!/b.html
     // This gets the b.html document from out of the a.jar file, that's
     // contained within the bar.jar file.
     // Also, the outermost "inner" URI may be a relative URI:
     //   jar:../relative.jar!/a.html
 
-    nsACString::const_iterator delim_begin (begin),
-                               delim_end   (end);
+    delim_begin = begin;
+    delim_end = end;
 
-    if (!RFindInReadable(NS_JAR_DELIMITER, delim_begin, delim_end))
+    if (!RFindInReadable(NS_JAR_DELIMITER, delim_begin, delim_end)) {
         return NS_ERROR_MALFORMED_URI;
+    }
 
     rv = ioServ->NewURI(Substring(begin, delim_begin), mCharsetHint.get(),
                         aBaseURL, getter_AddRefs(mJARFile));
     if (NS_FAILED(rv)) return rv;
 
     NS_TryToSetImmutable(mJARFile);
 
     // skip over any extra '/' chars
--- a/modules/libjar/test/unit/test_bug1328865.js
+++ b/modules/libjar/test/unit/test_bug1328865.js
@@ -6,19 +6,43 @@
 
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 var Cu = Components.utils;
 Cu.import("resource://gre/modules/NetUtil.jsm");
 
 // Check that reading non existant inner jars results in the right error
 
-function run_test() {
+add_task(async function() {
   var file = do_get_file("data/test_bug597702.zip");
   var ios = Cc["@mozilla.org/network/io-service;1"].
             getService(Ci.nsIIOService);
   var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
   var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello#!/ignore%20this%20part";
   var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
   var instr = goodChannel.open2();
 
   ok(!!instr, "Should be able to open channel");
-}
+});
+
+add_task(async function() {
+  var file = do_get_file("data/test_bug597702.zip");
+  var ios = Cc["@mozilla.org/network/io-service;1"].
+            getService(Ci.nsIIOService);
+  var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
+  var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello?ignore%20this%20part!/";
+  var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
+  var instr = goodChannel.open2();
+
+  ok(!!instr, "Should be able to open channel");
+});
+
+add_task(async function() {
+  var file = do_get_file("data/test_bug597702.zip");
+  var ios = Cc["@mozilla.org/network/io-service;1"].
+            getService(Ci.nsIIOService);
+  var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
+  var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello?ignore#this!/part";
+  var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
+  var instr = goodChannel.open2();
+
+  ok(!!instr, "Should be able to open channel");
+});