Bug 1305204 - (Part 3) Backout bug 1275746 a=backout draft
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 24 Oct 2016 23:01:10 +0200
changeset 428983 8c51dbbb7db324cc0226ac86e13c111cad79744f
parent 428982 160f1c56c493752d5b822d8369603d75f4846185
child 534865 afde229370539b5f77104c4df1b962591127843e
push id33448
push uservalentin.gosu@gmail.com
push dateMon, 24 Oct 2016 21:36:18 +0000
reviewersbackout
bugs1305204, 1275746
milestone50.0
Bug 1305204 - (Part 3) Backout bug 1275746 a=backout MozReview-Commit-ID: B627xyv9BRm
netwerk/base/nsStandardURL.cpp
netwerk/test/unit/test_URIs.js
netwerk/test/unit/test_standardurl.js
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1337,21 +1337,16 @@ nsStandardURL::SetSpec(const nsACString 
     // parse the given URL...
     nsresult rv = ParseURL(spec, specLength);
     if (NS_SUCCEEDED(rv)) {
         // finally, use the URLSegment member variables to build a normalized
         // copy of |spec|
         rv = BuildNormalizedSpec(spec);
     }
 
-    // Make sure that a URLTYPE_AUTHORITY has a non-empty hostname.
-    if (mURLType == URLTYPE_AUTHORITY && mHost.mLen == -1) {
-        rv = NS_ERROR_MALFORMED_URI;
-    }
-
     if (NS_FAILED(rv)) {
         Clear();
         // If parsing the spec has failed, restore the old URL
         // so we don't end up with an empty URL.
         CopyMembers(&prevURL, eHonorRef, EmptyCString());
         return rv;
     }
 
@@ -2929,36 +2924,30 @@ nsStandardURL::SetFile(nsIFile *file)
     NS_ENSURE_ARG_POINTER(file);
 
     nsresult rv;
     nsAutoCString url;
 
     rv = net_GetURLSpecFromFile(file, url);
     if (NS_FAILED(rv)) return rv;
 
-    uint32_t oldURLType = mURLType;
-    uint32_t oldDefaultPort = mDefaultPort;
-    rv = Init(nsIStandardURL::URLTYPE_NO_AUTHORITY, -1, url, nullptr, nullptr);
-
-    if (NS_FAILED(rv)) {
-        // Restore the old url type and default port if the call to Init fails.
-        mURLType = oldURLType;
-        mDefaultPort = oldDefaultPort;
-        return rv;
-    }
+    SetSpec(url);
+
+    rv = Init(mURLType, mDefaultPort, url, nullptr, nullptr);
 
     // must clone |file| since its value is not guaranteed to remain constant
-    InvalidateCache();
-    if (NS_FAILED(file->Clone(getter_AddRefs(mFile)))) {
-        NS_WARNING("nsIFile::Clone failed");
-        // failure to clone is not fatal (GetFile will generate mFile)
-        mFile = nullptr;
+    if (NS_SUCCEEDED(rv)) {
+        InvalidateCache();
+        if (NS_FAILED(file->Clone(getter_AddRefs(mFile)))) {
+            NS_WARNING("nsIFile::Clone failed");
+            // failure to clone is not fatal (GetFile will generate mFile)
+            mFile = 0;
+        }
     }
-
-    return NS_OK;
+    return rv;
 }
 
 //----------------------------------------------------------------------------
 // nsStandardURL::nsIStandardURL
 //----------------------------------------------------------------------------
 
 inline bool
 IsUTFCharset(const char *aCharset)
--- a/netwerk/test/unit/test_URIs.js
+++ b/netwerk/test/unit/test_URIs.js
@@ -87,16 +87,28 @@ var gTests = [
     nsIURL:  true, nsINestedURI: false },
   { spec:    "file:///dir/dir2/",
     scheme:  "file",
     prePath: "file://",
     path:    "/dir/dir2/data/text/plain,2",
     ref:     "",
     relativeURI: "data/text/plain,2",
     nsIURL:  true, nsINestedURI: false },
+  { spec:    "ftp://",
+    scheme:  "ftp",
+    prePath: "ftp://",
+    path:    "/",
+    ref:     "",
+    nsIURL:  true, nsINestedURI: false },
+  { spec:    "ftp:///",
+    scheme:  "ftp",
+    prePath: "ftp://",
+    path:    "/",
+    ref:     "",
+    nsIURL:  true, nsINestedURI: false },
   { spec:    "ftp://ftp.mozilla.org/pub/mozilla.org/README",
     scheme:  "ftp",
     prePath: "ftp://ftp.mozilla.org",
     path:    "/pub/mozilla.org/README",
     ref:     "",
     nsIURL:  true, nsINestedURI: false },
   { spec:    "ftp://foo:bar@ftp.mozilla.org:100/pub/mozilla.org/README",
     scheme:  "ftp",
@@ -126,16 +138,28 @@ var gTests = [
     ref:     "",
     nsIURL:  true, nsINestedURI: false },
   { spec:    "gopher://mozilla.org/",
     scheme:  "gopher",
     prePath: "gopher:",
     path:    "//mozilla.org/",
     ref:     "",
     nsIURL:  false, nsINestedURI: false },
+  { spec:    "http://",
+    scheme:  "http",
+    prePath: "http://",
+    path:    "/",
+    ref:     "",
+    nsIURL:  true, nsINestedURI: false },
+  { spec:    "http:///",
+    scheme:  "http",
+    prePath: "http://",
+    path:    "/",
+    ref:     "",
+    nsIURL:  true, nsINestedURI: false },
   { spec:    "http://www.example.com/",
     scheme:  "http",
     prePath: "http://www.example.com",
     path:    "/",
     ref:     "",
     nsIURL:  true, nsINestedURI: false },
   { spec:    "http://www.exa\nmple.com/",
     scheme:  "http",
--- a/netwerk/test/unit/test_standardurl.js
+++ b/netwerk/test/unit/test_standardurl.js
@@ -316,24 +316,16 @@ add_test(function test_backslashReplacem
   url = stringToURL("http:\\\\test.com\\example.org/path\\to/file");
   do_check_eq(url.spec, "http://test.com/example.org/path/to/file");
   do_check_eq(url.host, "test.com");
   do_check_eq(url.path, "/example.org/path/to/file");
 
   run_next_test();
 });
 
-add_test(function test_authority_host()
-{
-  Assert.throws(() => { stringToURL("http:"); }, "TYPE_AUTHORITY should have host");
-  Assert.throws(() => { stringToURL("http:///"); }, "TYPE_AUTHORITY should have host");
-
-  run_next_test();
-});
-
 add_test(function test_trim_C0_and_space()
 {
   var url = stringToURL("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f http://example.com/ \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f ");
   do_check_eq(url.spec, "http://example.com/");
   url.spec = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f http://test.com/ \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f ";
   do_check_eq(url.spec, "http://test.com/");
   Assert.throws(() => { url.spec = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19 "; }, "set empty spec");
   run_next_test();