Bug 431890: nsStandardURL::SetSpec does not fail when host contains leading space " ". r+sr=cbiesinger
authorMagnus Melin <mkmelin@iki.fi>
Sun, 14 Sep 2008 21:15:06 +0300
changeset 19242 19030b97ca13c342e5116c128cbe604d2905c0ab
parent 19241 07cb359d26bca3599eb31da36cf52085c23edf4f
child 19243 f50f7928622d8b1ae530d97d0c3714e4f64a612a
push id2052
push usermkmelin@iki.fi
push dateSun, 14 Sep 2008 18:15:43 +0000
treeherdermozilla-central@19030b97ca13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs431890
milestone1.9.1b1pre
Bug 431890: nsStandardURL::SetSpec does not fail when host contains leading space " ". r+sr=cbiesinger
netwerk/base/src/nsStandardURL.cpp
netwerk/test/unit/test_bug261425.js
--- a/netwerk/base/src/nsStandardURL.cpp
+++ b/netwerk/base/src/nsStandardURL.cpp
@@ -490,16 +490,18 @@ nsStandardURL::BuildNormalizedSpec(const
     // already point to a [ ] delimited IPv6 address literal.
     // However, perform Unicode normalization on it, as IDN does.
     mHostEncoding = eEncoding_ASCII;
     if (mHost.mLen > 0) {
         const nsCSubstring& tempHost =
             Substring(spec + mHost.mPos, spec + mHost.mPos + mHost.mLen);
         if (tempHost.FindChar('\0') != kNotFound)
             return NS_ERROR_MALFORMED_URI;  // null embedded in hostname
+        if (tempHost.FindChar(' ') != kNotFound)
+            return NS_ERROR_MALFORMED_URI;  // don't allow spaces in the hostname
         if ((useEncHost = NormalizeIDN(tempHost, encHost)))
             approxLen += encHost.Length();
         else
             approxLen += mHost.mLen;
     }
 
     //
     // generate the normalized URL string
--- a/netwerk/test/unit/test_bug261425.js
+++ b/netwerk/test/unit/test_bug261425.js
@@ -10,20 +10,18 @@ function run_test() {
 
   var success = false;
   try {
     newURI.spec = "http: //foo.com";
   }
   catch (e) {
     success = e.result == Cr.NS_ERROR_MALFORMED_URI;
   }
-  if (!success) {
-    // This is failing: bug 431890
-    //do_throw("We didn't throw NS_ERROR_MALFORMED_URI when a space was passed in the hostname!");
-  }
+  if (!success)
+    do_throw("We didn't throw NS_ERROR_MALFORMED_URI when a space was passed in the hostname!");
 
   success = false;
   try {
     newURI.host = " foo.com";
   }
   catch (e) {
     success = e.result == Cr.NS_ERROR_MALFORMED_URI;
   }