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

MozReview-Commit-ID: GYHpakKPEbe

--HG--
extra : rebase_source : 521966b446284fbe215dfc8518acafc5de9ded5c
This commit is contained in:
Valentin Gosu 2018-02-26 20:43:45 +01:00
Родитель 7bd0336d01
Коммит 710c2e2fc9
7 изменённых файлов: 37 добавлений и 15 удалений

Просмотреть файл

@ -506,14 +506,19 @@ Link::SetHostname(const nsAString &aHostname)
void
Link::SetPathname(const nsAString &aPathname)
{
nsCOMPtr<nsIURI> uri(GetURIToMutate());
nsCOMPtr<nsIURI> uri(GetURI());
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
if (!url) {
// Ignore failures to be compatible with NS4.
return;
}
(void)url->SetFilePath(NS_ConvertUTF16toUTF8(aPathname));
nsresult rv = NS_MutateURI(uri)
.SetFilePath(NS_ConvertUTF16toUTF8(aPathname))
.Finalize(uri);
if (NS_FAILED(rv)) {
return;
}
SetHrefAttribute(uri);
}

Просмотреть файл

@ -600,14 +600,19 @@ Location::SetPathname(const nsAString& aPathname,
}
nsCOMPtr<nsIURI> uri;
aRv = GetWritableURI(getter_AddRefs(uri));
aRv = GetURI(getter_AddRefs(uri));
if (NS_WARN_IF(aRv.Failed()) || !uri) {
return;
}
if (NS_SUCCEEDED(uri->SetFilePath(NS_ConvertUTF16toUTF8(aPathname)))) {
aRv = SetURI(uri);
nsresult rv = NS_MutateURI(uri)
.SetFilePath(NS_ConvertUTF16toUTF8(aPathname))
.Finalize(uri);
if (NS_FAILED(rv)) {
return;
}
aRv = SetURI(uri);
}
void

Просмотреть файл

@ -404,7 +404,9 @@ URLMainThread::SetPathname(const nsAString& aPathname, ErrorResult& aRv)
{
// Do not throw!
mURI->SetFilePath(NS_ConvertUTF16toUTF8(aPathname));
Unused << NS_MutateURI(mURI)
.SetFilePath(NS_ConvertUTF16toUTF8(aPathname))
.Finalize(mURI);
}
void

Просмотреть файл

@ -664,7 +664,9 @@ nsJARURI::GetFilePath(nsACString& filePath)
NS_IMETHODIMP
nsJARURI::SetFilePath(const nsACString& filePath)
{
return mJAREntry->SetFilePath(filePath);
return NS_MutateURI(mJAREntry)
.SetFilePath(filePath)
.Finalize(mJAREntry);
}
NS_IMETHODIMP

Просмотреть файл

@ -1147,7 +1147,12 @@ nsFtpState::SetContentType()
nsAutoCString filePath;
if(NS_SUCCEEDED(url->GetFilePath(filePath))) {
filePath.Append('/');
url->SetFilePath(filePath);
nsresult rv = NS_MutateURI(url)
.SetFilePath(filePath)
.Finalize(url);
if (NS_SUCCEEDED(rv)) {
mChannel->UpdateURI(url);
}
}
}
return mChannel->SetContentType(

Просмотреть файл

@ -303,7 +303,7 @@ add_test(function test_hugeStringThrows()
let hugeString = new Array(maxLen + 1).fill("a").join("");
let properties = ["scheme", "userPass", "username",
"password", "host", "ref",
"query", "filePath"];
"query"];
for (let prop of properties) {
Assert.throws(() => url[prop] = hugeString,
/NS_ERROR_MALFORMED_URI/,
@ -312,6 +312,7 @@ add_test(function test_hugeStringThrows()
let setters = [
{ method: "setSpec", qi: Ci.nsIURIMutator },
{ method: "setFilePath", qi: Ci.nsIURIMutator },
{ method: "setHostPort", qi: Ci.nsIURIMutator },
{ method: "setPathQueryRef", qi: Ci.nsIURIMutator },
{ method: "setFileName", qi: Ci.nsIURLMutator },
@ -335,7 +336,7 @@ add_test(function test_filterWhitespace()
// These setters should escape \r\n\t, not filter them.
var url = stringToURL("http://test.com/path?query#hash");
url.filePath = "pa\r\n\tth";
url = url.mutate().setFilePath("pa\r\n\tth").finalize();
Assert.equal(url.spec, "http://test.com/pa%0D%0A%09th?query#hash");
url.query = "qu\r\n\tery";
Assert.equal(url.spec, "http://test.com/pa%0D%0A%09th?qu%0D%0A%09ery#hash");
@ -404,7 +405,7 @@ add_test(function test_encode_C0_and_space()
// Additionally, we need to check the setters.
var url = stringToURL("http://example.com/path?query#hash");
url.filePath = "pa\0th";
url = url.mutate().setFilePath("pa\0th").finalize();
Assert.equal(url.spec, "http://example.com/pa%00th?query#hash");
url.query = "qu\0ery";
Assert.equal(url.spec, "http://example.com/pa%00th?qu%00ery#hash");

Просмотреть файл

@ -1090,10 +1090,12 @@ function getDefaultExtension(aFilename, aURI, aContentType) {
return ""; // temporary fix for bug 120327
// First try the extension from the filename
const stdURLContractID = "@mozilla.org/network/standard-url;1";
const stdURLIID = Components.interfaces.nsIURL;
var url = Components.classes[stdURLContractID].createInstance(stdURLIID);
url.filePath = aFilename;
var url = Components.classes["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Components.interfaces.nsIURIMutator)
.setSpec("http://example.com") // construct the URL
.setFilePath(aFilename)
.finalize()
.QueryInterface(Components.interfaces.nsIURL);
var ext = url.fileExtension;