Bug 1456421 - Align XHR username/password precedence rules with current spec. r?baku
MozReview-Commit-ID: FXCFoNhCVJz
--- 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
-