Bug 1386195 - mDisplayHost must be initalized even when host does not start with `xn--` r=dragana
authorValentin Gosu <valentin.gosu@gmail.com>
Tue, 01 Aug 2017 14:24:53 +0300
changeset 372216 407356a3597e87d9547ccab666b41a6e8780672a
parent 372215 7d01cd53da023a9080cb7a529a4190c51dd97d97
child 372217 13750b02d0219aec45da8bbe24aaa235593d5696
push id32269
push userkwierso@gmail.com
push dateTue, 01 Aug 2017 20:17:29 +0000
treeherdermozilla-central@a3e675a3b10a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1386195
milestone56.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 1386195 - mDisplayHost must be initalized even when host does not start with `xn--` r=dragana MozReview-Commit-ID: HnDqw8oyE2r
netwerk/base/nsStandardURL.cpp
netwerk/test/unit/test_standardurl.js
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1426,33 +1426,33 @@ nsStandardURL::CheckIfHostIsAscii()
 {
     nsresult rv;
     if (mCheckedIfHostA) {
         return NS_OK;
     }
 
     mCheckedIfHostA = true;
 
-    // If the hostname doesn't begin with `xn--` we are sure it is ASCII.
-    if (!StringBeginsWith(Host(), NS_LITERAL_CSTRING("xn--"))) {
-        return NS_OK;
-    }
-
     if (!gIDN) {
         return NS_ERROR_NOT_INITIALIZED;
     }
 
+    nsAutoCString displayHost;
     bool isAscii;
-    rv = gIDN->ConvertToDisplayIDN(Host(), &isAscii, mDisplayHost);
+    rv = gIDN->ConvertToDisplayIDN(Host(), &isAscii, displayHost);
     if (NS_FAILED(rv)) {
         mDisplayHost.Truncate();
         mCheckedIfHostA = false;
         return rv;
     }
 
+    if (!isAscii) {
+        mDisplayHost = displayHost;
+    }
+
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsStandardURL::GetDisplaySpec(nsACString &aUnicodeSpec)
 {
     CheckIfHostIsAscii();
     aUnicodeSpec.Assign(mSpec);
--- a/netwerk/test/unit/test_standardurl.js
+++ b/netwerk/test/unit/test_standardurl.js
@@ -520,16 +520,20 @@ add_test(function test_idna_host() {
   equal(url.asciiHostPort, "xn--lt-uia.example.org:8080");
   equal(url.asciiSpec, "http://user:password@xn--lt-uia.example.org:8080/path?query#etc");
 
   url.ref = ""; // SetRef calls InvalidateCache()
   equal(url.spec, "http://user:password@ält.example.org:8080/path?query");
   equal(url.displaySpec, "http://user:password@ält.example.org:8080/path?query");
   equal(url.asciiSpec, "http://user:password@xn--lt-uia.example.org:8080/path?query");
 
+  url = stringToURL("http://user:password@www.ält.com:8080/path?query#etc");
+  url.ref = "";
+  equal(url.spec, "http://user:password@www.ält.com:8080/path?query");
+
   // We also check that the default behaviour changes once we filp the pref
   gPrefs.setBoolPref("network.standard-url.punycode-host", true);
 
   url = stringToURL("http://user:password@ält.example.org:8080/path?query#etc");
   equal(url.host, "xn--lt-uia.example.org");
   equal(url.hostPort, "xn--lt-uia.example.org:8080");
   equal(url.prePath, "http://user:password@xn--lt-uia.example.org:8080");
   equal(url.spec, "http://user:password@xn--lt-uia.example.org:8080/path?query#etc");
@@ -544,10 +548,14 @@ add_test(function test_idna_host() {
   equal(url.asciiHostPort, "xn--lt-uia.example.org:8080");
   equal(url.asciiSpec, "http://user:password@xn--lt-uia.example.org:8080/path?query#etc");
 
   url.ref = ""; // SetRef calls InvalidateCache()
   equal(url.spec, "http://user:password@xn--lt-uia.example.org:8080/path?query");
   equal(url.displaySpec, "http://user:password@ält.example.org:8080/path?query");
   equal(url.asciiSpec, "http://user:password@xn--lt-uia.example.org:8080/path?query");
 
+  url = stringToURL("http://user:password@www.ält.com:8080/path?query#etc");
+  url.ref = "";
+  equal(url.spec, "http://user:password@www.xn--lt-uia.com:8080/path?query");
+
   run_next_test();
 });