Bug 1314859 - SetHost should also call NormalizeIPv4 r=mcmanus
authorValentin Gosu <valentin.gosu@gmail.com>
Sun, 06 Nov 2016 23:26:04 +0100
changeset 321321 4f657d9e8c8204d43f0cb73f942857f569cba215
parent 321320 af46e53372abd9a03188e580dbe76ac54f209ed6
child 321322 db20b5de138f842350bc8305c9a98e2bad8f94e3
push id83554
push uservalentin.gosu@gmail.com
push dateSun, 06 Nov 2016 22:26:22 +0000
treeherdermozilla-inbound@4f657d9e8c82 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1314859
milestone52.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 1314859 - SetHost should also call NormalizeIPv4 r=mcmanus MozReview-Commit-ID: 79sQrld6TBG
netwerk/base/nsStandardURL.cpp
netwerk/test/unit/test_standardurl.js
testing/web-platform/meta/url/url-setters.html.ini
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1923,16 +1923,22 @@ nsStandardURL::SetHost(const nsACString 
 
     uint32_t len;
     nsAutoCString hostBuf;
     nsresult rv = NormalizeIDN(flat, hostBuf);
     if (NS_FAILED(rv)) {
         return rv;
     }
 
+    nsAutoCString ipString;
+    rv = NormalizeIPv4(hostBuf, ipString);
+    if (NS_SUCCEEDED(rv)) {
+      hostBuf = ipString;
+    }
+
     // NormalizeIDN always copies if the call was successful
     host = hostBuf.get();
     len = hostBuf.Length();
 
     if (!ValidIPv6orHostname(host, len)) {
         return NS_ERROR_MALFORMED_URI;
     }
 
--- a/netwerk/test/unit/test_standardurl.js
+++ b/netwerk/test/unit/test_standardurl.js
@@ -174,19 +174,19 @@ add_test(function test_ipv6()
   url = stringToURL("http://example.com");
   url.hostPort = "[2001::1]:30";
   do_check_eq(url.host, "2001::1");
   do_check_eq(url.port, 30);
   do_check_eq(url.hostPort, "[2001::1]:30");
 
   url = stringToURL("http://example.com");
   url.hostPort = "2001:1";
-  do_check_eq(url.host, "2001");
+  do_check_eq(url.host, "0.0.7.209");
   do_check_eq(url.port, 1);
-  do_check_eq(url.hostPort, "2001:1");
+  do_check_eq(url.hostPort, "0.0.7.209:1");
   run_next_test();
 });
 
 add_test(function test_ipv6_fail()
 {
   var url = stringToURL("http://example.com");
 
   Assert.throws(() => { url.host = "2001::1"; }, "missing brackets");
--- a/testing/web-platform/meta/url/url-setters.html.ini
+++ b/testing/web-platform/meta/url/url-setters.html.ini
@@ -58,37 +58,31 @@
     expected: FAIL
 
   [Setting <view-source+http://example.net/foo>.host = '' The empty host is OK for non-special schemes]
     expected: FAIL
 
   [Setting <a:/foo>.host = 'example.net' Path-only URLs can gain a host]
     expected: FAIL
 
-  [Setting <http://example.net>.host = '0x7F000001:8080' IPv4 address syntax is normalized]
-    expected: FAIL
-
   [Setting <http://example.net>.host = '[::0:01\]:2' IPv6 address syntax is normalized]
     expected: FAIL
 
   [Setting <view-source+http://example.net/path>.host = 'example.com\\stuff' \\ is not a delimiter for non-special schemes, and it’s invalid in a domain]
     expected: FAIL
 
   [Setting <view-source+http://example.net/path>.host = 'example.com:8080stuff2' Anything other than ASCII digit stops the port parser in a setter but is not an error]
     expected: FAIL
 
   [Setting <view-source+http://example.net/foo>.hostname = '' The empty host is OK for non-special schemes]
     expected: FAIL
 
   [Setting <a:/foo>.hostname = 'example.net' Path-only URLs can gain a host]
     expected: FAIL
 
-  [Setting <http://example.net:8080>.hostname = '0x7F000001' IPv4 address syntax is normalized]
-    expected: FAIL
-
   [Setting <http://example.net>.hostname = '[::0:01\]' IPv6 address syntax is normalized]
     expected: FAIL
 
   [Setting <http://example.net/path>.hostname = 'example.com:8080' Stuff after a : delimiter is ignored]
     expected: FAIL
 
   [Setting <http://example.net:8080/path>.hostname = 'example.com:' Stuff after a : delimiter is ignored]
     expected: FAIL