diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 769afb2f68a92..4c03cf63c3122 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -1862,18 +1862,10 @@ nsresult NS_NewURI(nsIURI** aURI, const nsACString& aSpec, } if (scheme.EqualsLiteral("file")) { - nsAutoCString buf(aSpec); -#if defined(XP_WIN) - buf.Truncate(); - if (!net_NormalizeFileURL(aSpec, buf)) { - buf = aSpec; - } -#endif - return NS_MutateURI(new nsStandardURL::Mutator()) .Apply(&nsIFileURLMutator::MarkFileURL) .Apply(&nsIStandardURLMutator::Init, - nsIStandardURL::URLTYPE_NO_AUTHORITY, -1, buf, aCharset, + nsIStandardURL::URLTYPE_NO_AUTHORITY, -1, aSpec, aCharset, aBaseURI, nullptr) .Finalize(aURI); } diff --git a/netwerk/base/nsURLHelper.cpp b/netwerk/base/nsURLHelper.cpp index 41bf0aa97762e..3850c6865a742 100644 --- a/netwerk/base/nsURLHelper.cpp +++ b/netwerk/base/nsURLHelper.cpp @@ -516,6 +516,11 @@ bool net_NormalizeFileURL(const nsACString& aURL, nsCString& aResultBuf) { aResultBuf += '/'; begin = s + 1; } + if (*s == '#') { + // Don't normalize any backslashes following the hash. + s = endIter.get(); + break; + } } if (writing && s > begin) aResultBuf.Append(begin, s - begin); diff --git a/netwerk/test/unit/test_URIs.js b/netwerk/test/unit/test_URIs.js index 0f53b1fc4a1b8..b9ec2b3f2d486 100644 --- a/netwerk/test/unit/test_URIs.js +++ b/netwerk/test/unit/test_URIs.js @@ -966,3 +966,15 @@ add_task(async function round_trip_invalid_ace_label() { uri = Services.io.newURI("http://a.b.c.XN--pokxncvks"); }, /NS_ERROR_MALFORMED_URI/); }); + +add_task(async function test_bug1843717() { + // Make sure file path normalization on windows + // doesn't affect the hash of the URL. + let base = Services.io.newURI("file:///abc\\def/"); + let uri = Services.io.newURI("foo\\bar#x\\y", null, base); + Assert.equal(uri.spec, "file:///abc/def/foo/bar#x\\y"); + uri = Services.io.newURI("foo\\bar#xy", null, base); + Assert.equal(uri.spec, "file:///abc/def/foo/bar#xy"); + uri = Services.io.newURI("foo\\bar#", null, base); + Assert.equal(uri.spec, "file:///abc/def/foo/bar#"); +});