Bug 1369317 - Make sure nsSimpleURI::SetPathQueryRef escapes its non-ASCII argument r=mcmanus

MozReview-Commit-ID: JBloDTiYFN

--HG--
extra : rebase_source : b465a6bff65297c2e119c3b0a262825788f8346a
This commit is contained in:
Valentin Gosu 2017-08-13 10:03:28 +02:00
parent 8d15eba8a4
commit 7fac981ff5
2 changed files with 19 additions and 4 deletions

View File

@ -312,7 +312,8 @@ nsSimpleURI::SetSpec(const nsACString &aSpec)
ToLowerCase(mScheme);
// This sets mPath, mQuery and mRef.
return SetPathQueryRef(Substring(spec, colonPos + 1));
return SetPathQueryRefEscaped(Substring(spec, colonPos + 1),
/* needsEscape = */ false);
}
NS_IMETHODIMP
@ -461,10 +462,22 @@ nsSimpleURI::SetPathQueryRef(const nsACString &aPath)
{
NS_ENSURE_STATE(mMutable);
return SetPathQueryRefEscaped(aPath, true);
}
nsresult
nsSimpleURI::SetPathQueryRefEscaped(const nsACString &aPath, bool aNeedsEscape)
{
nsresult rv;
nsAutoCString path;
if (!path.Assign(aPath, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
if (aNeedsEscape) {
rv = NS_EscapeURL(aPath, esc_OnlyNonASCII, path, fallible);
if (NS_FAILED(rv)) {
return rv;
}
} else {
path.Assign(aPath);
}
int32_t queryPos = path.FindChar('?');
int32_t hashPos = path.FindChar('#');
@ -502,7 +515,7 @@ nsSimpleURI::SetPathQueryRef(const nsACString &aPath)
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = SetQuery(query);
rv = SetQuery(query);
if (NS_FAILED(rv)) {
return rv;
}

View File

@ -100,6 +100,8 @@ protected:
const nsACString &newRef,
nsIURI** clone);
nsresult SetPathQueryRefEscaped(const nsACString &aPath, bool aNeedsEscape);
nsCString mScheme;
nsCString mPath; // NOTE: mPath does not include ref, as an optimization
nsCString mRef; // so that URIs with different refs can share string data.