Bug 1328865 - Make nsJARURI::SetSpecWithBase ignore URL fragments. r=valentin
As otherwise it could wrongly find !/ delimiters with that.
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -283,16 +283,25 @@ 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 frag = begin;
+ while (frag != end && *frag != '#') {
+ ++frag;
+ }
+ if (frag != end) {
+ // there was a fragment, 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
@@ -307,16 +316,17 @@ nsJARURI::SetSpecWithBase(const nsACStri
if (NS_FAILED(rv)) return rv;
NS_TryToSetImmutable(mJARFile);
// skip over any extra '/' chars
while (*delim_end == '/')
++delim_end;
+ aSpec.EndReading(end); // set to the original 'end'
return SetJAREntry(Substring(delim_end, end));
}
NS_IMETHODIMP
nsJARURI::GetPrePath(nsACString &prePath)
{
prePath = NS_JAR_SCHEME;
return NS_OK;
new file mode 100644
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug1328865.js
@@ -0,0 +1,24 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+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() {
+ 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");
+}
--- a/modules/libjar/test/unit/xpcshell.ini
+++ b/modules/libjar/test/unit/xpcshell.ini
@@ -36,8 +36,9 @@ skip-if = os == "mac"
[test_corrupt_541828.js]
[test_corrupt_1211262.js]
[test_crx.js]
[test_dirjar_bug525755.js]
[test_jarinput_stream_zipreader_reference.js]
[test_not_found.js]
[test_uncompressed.js]
[test_umlaute.js]
+[test_bug1328865.js]