Bug 1433958 - Change code that sets nsIURI.userPass to use nsIURIMutator r=mayhemer

* Code in XMLHttpRequestMainThread is converted to set the username and password individually. This is because when the parameters are empty, it ended up calling SetUserPass(":") which always returns an error.

MozReview-Commit-ID: 3cK5HeyzjFE
This commit is contained in:
Valentin Gosu
2018-02-26 20:43:46 +01:00
parent d4f4bcfafd
commit b9160f5ce8
17 changed files with 79 additions and 53 deletions

View File

@@ -40,6 +40,7 @@
#include "nsReadableUtils.h"
#include "nsIURI.h"
#include "nsIURIMutator.h"
#include "nsILoadGroup.h"
#include "nsNetUtil.h"
#include "nsStringStream.h"
@@ -1483,15 +1484,12 @@ XMLHttpRequestMainThread::Open(const nsACString& aMethod,
nsAutoCString host;
parsedURL->GetHost(host);
if (!host.IsEmpty()) {
nsAutoCString userpass;
if (!aUsername.IsVoid()) {
CopyUTF16toUTF8(aUsername, userpass);
if (!aUsername.IsVoid() || !aPassword.IsVoid()) {
Unused << NS_MutateURI(parsedURL)
.SetUsername(NS_ConvertUTF16toUTF8(aUsername))
.SetPassword(NS_ConvertUTF16toUTF8(aPassword))
.Finalize(parsedURL);
}
userpass.AppendLiteral(":");
if (!aPassword.IsVoid()) {
AppendUTF16toUTF8(aPassword, userpass);
}
parsedURL->SetUserPass(userpass);
}
// Step 9