Bug 1456421 - Align XHR username/password precedence rules with current spec. r?baku draft
authorThomas Wisniewski <wisniewskit@gmail.com>
Tue, 31 Jul 2018 09:49:00 -0400
changeset 825241 9f41a283bf26a79f235cb04e7525146ad1355ace
parent 825071 d57a89840dbb4ae0611d0d9a1e6d27e3d0a99e00
push id118040
push userwisniewskit@gmail.com
push dateWed, 01 Aug 2018 03:43:09 +0000
reviewersbaku
bugs1456421
milestone63.0a1
Bug 1456421 - Align XHR username/password precedence rules with current spec. r?baku MozReview-Commit-ID: FXCFoNhCVJz
dom/xhr/XMLHttpRequestMainThread.cpp
testing/web-platform/meta/xhr/send-authentication-competing-names-passwords.htm.ini
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -1467,23 +1467,25 @@ XMLHttpRequestMainThread::Open(const nsA
 
   // Step 7
   // This is already handled by the other Open() method, which passes
   // username and password in as NullStrings.
 
   // Step 8
   nsAutoCString host;
   parsedURL->GetHost(host);
-  if (!host.IsEmpty()) {
-    if (!aUsername.IsVoid() || !aPassword.IsVoid()) {
-      Unused << NS_MutateURI(parsedURL)
-                  .SetUsername(NS_ConvertUTF16toUTF8(aUsername))
-                  .SetPassword(NS_ConvertUTF16toUTF8(aPassword))
-                  .Finalize(parsedURL);
+  if (!host.IsEmpty() && (!aUsername.IsVoid() || !aPassword.IsVoid())) {
+    auto mutator = NS_MutateURI(parsedURL);
+    if (!aUsername.IsVoid()) {
+      mutator.SetUsername(NS_ConvertUTF16toUTF8(aUsername));
     }
+    if (!aPassword.IsVoid()) {
+      mutator.SetPassword(NS_ConvertUTF16toUTF8(aPassword));
+    }
+    Unused << mutator.Finalize(parsedURL);
   }
 
   // Step 9
   if (!aAsync && HasOrHasHadOwner() && (mTimeoutMilliseconds ||
        mResponseType != XMLHttpRequestResponseType::_empty)) {
     if (mTimeoutMilliseconds) {
       LogMessage("TimeoutSyncXHRWarning", GetOwner());
     }
--- a/testing/web-platform/meta/xhr/send-authentication-competing-names-passwords.htm.ini
+++ b/testing/web-platform/meta/xhr/send-authentication-competing-names-passwords.htm.ini
@@ -6,17 +6,8 @@
     expected: FAIL
 
   [XMLHttpRequest user/pass options: pass in URL, user in open()]
     expected: FAIL
 
   [XMLHttpRequest user/pass options: pass in URL, user/pass in open()]
     expected: FAIL
 
-  [XMLHttpRequest user/pass options: user in URL, pass in open()]
-    expected: FAIL
-
-  [XMLHttpRequest user/pass options: user/pass in URL; user in open()]
-    expected: FAIL
-
-  [XMLHttpRequest user/pass options: user/pass in URL; pass in open()]
-    expected: FAIL
-