From 7f899f94dd50887ce03e7ff7322d6063cc4e9d85 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Fri, 28 Jun 2019 13:12:49 +0000 Subject: [PATCH] Bug 1559356 - Make sure dweb URLs have a proper host r=kershaw We want dweb URLs to continue working as before bug 1536744 landed. So we make sure to instantiate it as an nsStandardURL. This is not a good long-term solution, as we don't want to hardcode all the various schemes that we want to behave properly. The fix would be to add a new spec-compliant nsIURI implementation, based on RustURL and use it for all unknown schemes. See bug 1561860 for a more complete solution. Differential Revision: https://phabricator.services.mozilla.com/D36168 --HG-- extra : moz-landing-system : lando --- netwerk/base/nsNetUtil.cpp | 4 ++++ netwerk/test/unit/test_URIs.js | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index ad0bc129ea23..e345e3363803 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -1861,6 +1861,10 @@ nsresult NS_NewURI(nsIURI** aURI, const nsACString& aSpec, .Finalize(aURI); } + if (scheme.EqualsLiteral("dweb") || scheme.EqualsLiteral("dat")) { + return NewStandardURI(aSpec, aCharset, aBaseURI, -1, aURI); + } + #if defined(MOZ_THUNDERBIRD) || defined(MOZ_SUITE) rv = NS_NewMailnewsURI(aURI, aSpec, aCharset, aBaseURI, aIOService); if (rv != NS_ERROR_UNKNOWN_PROTOCOL) { diff --git a/netwerk/test/unit/test_URIs.js b/netwerk/test/unit/test_URIs.js index f59ba0f45bec..e61e168730db 100644 --- a/netwerk/test/unit/test_URIs.js +++ b/netwerk/test/unit/test_URIs.js @@ -639,6 +639,15 @@ function check_resolve() { Assert.equal(uri.spec, "tel::+371 27028456"); } +function test_extra_protocols() { + let url = gIoService.newURI("dweb://example.com/test"); + Assert.equal(url.host, "example.com"); + url = gIoService.newURI("dat://41f8a987cfeba80a037e51cc8357d513b62514de36f2f9b3d3eeec7a8fb3b5a5/"); + Assert.equal(url.host, "41f8a987cfeba80a037e51cc8357d513b62514de36f2f9b3d3eeec7a8fb3b5a5"); + url = gIoService.newURI("dat://example.com/test"); + Assert.equal(url.host, "example.com"); +} + // TEST MAIN FUNCTION // ------------------ function run_test() @@ -648,6 +657,7 @@ function run_test() check_schemeIsNull(); check_mozextension_query(); check_resolve(); + test_extra_protocols(); // UTF-8 check - From bug 622981 // ASCII