Bug 1415574 - make nsJARURI::SetSpecWithBase ignore URL string; r?bagder draft
authorLiang-Heng Chen <xeonchen@gmail.com>
Tue, 21 Nov 2017 14:26:43 +0800
changeset 709543 0a746b4b85a952eaabce21d246183ed525bd17e5
parent 706025 a21f4e2ce5186e2dc9ee411b07e9348866b4ef30
child 743451 d0be9ce29335b878981f8858372258adca277fb1
push id92682
push userbmo:xeonchen@mozilla.com
push dateFri, 08 Dec 2017 08:16:46 +0000
reviewersbagder
bugs1415574
milestone59.0a1
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");
+});