mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 06:09:19 +00:00
Bug 1884941 - Add an option to URLParams::Parse() for if it should decode the parameters or not. r=anti-tracking-reviewers,necko-reviewers,valentin,timhuang.
Differential Revision: https://phabricator.services.mozilla.com/D204914
This commit is contained in:
parent
f81c16c09c
commit
6053848bf6
@ -324,7 +324,7 @@ bool OriginAttributes::PopulateFromSuffix(const nsACString& aStr) {
|
|||||||
MOZ_RELEASE_ASSERT(mPartitionKey.IsEmpty());
|
MOZ_RELEASE_ASSERT(mPartitionKey.IsEmpty());
|
||||||
|
|
||||||
return URLParams::Parse(
|
return URLParams::Parse(
|
||||||
Substring(aStr, 1, aStr.Length() - 1),
|
Substring(aStr, 1, aStr.Length() - 1), true,
|
||||||
[this](const nsAString& aName, const nsAString& aValue) {
|
[this](const nsAString& aName, const nsAString& aValue) {
|
||||||
if (aName.EqualsLiteral("inBrowser")) {
|
if (aName.EqualsLiteral("inBrowser")) {
|
||||||
if (!aValue.EqualsLiteral("1")) {
|
if (!aValue.EqualsLiteral("1")) {
|
||||||
|
@ -422,7 +422,7 @@ already_AddRefed<FormData> BodyUtil::ConsumeFormData(
|
|||||||
if (isValidUrlEncodedMimeType) {
|
if (isValidUrlEncodedMimeType) {
|
||||||
RefPtr<FormData> fd = new FormData(aParent);
|
RefPtr<FormData> fd = new FormData(aParent);
|
||||||
DebugOnly<bool> status = URLParams::Parse(
|
DebugOnly<bool> status = URLParams::Parse(
|
||||||
aStr, [&fd](const nsAString& aName, const nsAString& aValue) {
|
aStr, true, [&fd](const nsAString& aName, const nsAString& aValue) {
|
||||||
ErrorResult rv;
|
ErrorResult rv;
|
||||||
fd->Append(aName, aValue, rv);
|
fd->Append(aName, aValue, rv);
|
||||||
MOZ_ASSERT(!rv.Failed());
|
MOZ_ASSERT(!rv.Failed());
|
||||||
|
@ -7658,7 +7658,7 @@ Result<bool, nsresult> UpgradeStorageFrom1_0To2_0Helper::MaybeRemoveAppsData(
|
|||||||
MOZ_ASSERT(originalSuffix[0] == '^');
|
MOZ_ASSERT(originalSuffix[0] == '^');
|
||||||
|
|
||||||
if (!URLParams::Parse(
|
if (!URLParams::Parse(
|
||||||
Substring(originalSuffix, 1, originalSuffix.Length() - 1),
|
Substring(originalSuffix, 1, originalSuffix.Length() - 1), true,
|
||||||
[](const nsAString& aName, const nsAString& aValue) {
|
[](const nsAString& aName, const nsAString& aValue) {
|
||||||
if (aName.EqualsLiteral("appId")) {
|
if (aName.EqualsLiteral("appId")) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -68,7 +68,7 @@ bool StorageOriginAttributes::PopulateFromSuffix(const nsACString& aStr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ok =
|
bool ok =
|
||||||
URLParams::Parse(Substring(aStr, 1, aStr.Length() - 1),
|
URLParams::Parse(Substring(aStr, 1, aStr.Length() - 1), true,
|
||||||
[this](const nsAString& aName, const nsAString& aValue) {
|
[this](const nsAString& aName, const nsAString& aValue) {
|
||||||
if (aName.EqualsLiteral("inBrowser")) {
|
if (aName.EqualsLiteral("inBrowser")) {
|
||||||
if (!aValue.EqualsLiteral("1")) {
|
if (!aValue.EqualsLiteral("1")) {
|
||||||
|
@ -1236,8 +1236,8 @@ void URLParams::DecodeString(const nsACString& aInput, nsAString& aOutput) {
|
|||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
bool URLParams::ParseNextInternal(const char*& aStart, const char* const aEnd,
|
bool URLParams::ParseNextInternal(const char*& aStart, const char* const aEnd,
|
||||||
nsAString* aOutDecodedName,
|
bool aShouldDecode, nsAString* aOutputName,
|
||||||
nsAString* aOutDecodedValue) {
|
nsAString* aOutputValue) {
|
||||||
nsDependentCSubstring string;
|
nsDependentCSubstring string;
|
||||||
|
|
||||||
const char* const iter = std::find(aStart, aEnd, '&');
|
const char* const iter = std::find(aStart, aEnd, '&');
|
||||||
@ -1267,9 +1267,14 @@ bool URLParams::ParseNextInternal(const char*& aStart, const char* const aEnd,
|
|||||||
name.Rebind(string, 0);
|
name.Rebind(string, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
DecodeString(name, *aOutDecodedName);
|
if (aShouldDecode) {
|
||||||
DecodeString(value, *aOutDecodedValue);
|
DecodeString(name, *aOutputName);
|
||||||
|
DecodeString(value, *aOutputValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConvertString(name, *aOutputName);
|
||||||
|
ConvertString(value, *aOutputValue);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1278,7 +1283,7 @@ bool URLParams::Extract(const nsACString& aInput, const nsAString& aName,
|
|||||||
nsAString& aValue) {
|
nsAString& aValue) {
|
||||||
aValue.SetIsVoid(true);
|
aValue.SetIsVoid(true);
|
||||||
return !URLParams::Parse(
|
return !URLParams::Parse(
|
||||||
aInput, [&aName, &aValue](const nsAString& name, nsString&& value) {
|
aInput, true, [&aName, &aValue](const nsAString& name, nsString&& value) {
|
||||||
if (aName == name) {
|
if (aName == name) {
|
||||||
aValue = std::move(value);
|
aValue = std::move(value);
|
||||||
return false;
|
return false;
|
||||||
@ -1291,7 +1296,7 @@ void URLParams::ParseInput(const nsACString& aInput) {
|
|||||||
// Remove all the existing data before parsing a new input.
|
// Remove all the existing data before parsing a new input.
|
||||||
DeleteAll();
|
DeleteAll();
|
||||||
|
|
||||||
URLParams::Parse(aInput, [this](nsString&& name, nsString&& value) {
|
URLParams::Parse(aInput, true, [this](nsString&& name, nsString&& value) {
|
||||||
mParams.AppendElement(Param{std::move(name), std::move(value)});
|
mParams.AppendElement(Param{std::move(name), std::move(value)});
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -257,19 +257,20 @@ class URLParams final {
|
|||||||
* true otherwise
|
* true otherwise
|
||||||
*/
|
*/
|
||||||
template <typename ParamHandler>
|
template <typename ParamHandler>
|
||||||
static bool Parse(const nsACString& aInput, ParamHandler aParamHandler) {
|
static bool Parse(const nsACString& aInput, bool aShouldDecode,
|
||||||
|
ParamHandler aParamHandler) {
|
||||||
const char* start = aInput.BeginReading();
|
const char* start = aInput.BeginReading();
|
||||||
const char* const end = aInput.EndReading();
|
const char* const end = aInput.EndReading();
|
||||||
|
|
||||||
while (start != end) {
|
while (start != end) {
|
||||||
nsAutoString decodedName;
|
nsAutoString name;
|
||||||
nsAutoString decodedValue;
|
nsAutoString value;
|
||||||
|
|
||||||
if (!ParseNextInternal(start, end, &decodedName, &decodedValue)) {
|
if (!ParseNextInternal(start, end, aShouldDecode, &name, &value)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!aParamHandler(std::move(decodedName), std::move(decodedValue))) {
|
if (!aParamHandler(std::move(name), std::move(value))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,8 +358,8 @@ class URLParams final {
|
|||||||
static void DecodeString(const nsACString& aInput, nsAString& aOutput);
|
static void DecodeString(const nsACString& aInput, nsAString& aOutput);
|
||||||
static void ConvertString(const nsACString& aInput, nsAString& aOutput);
|
static void ConvertString(const nsACString& aInput, nsAString& aOutput);
|
||||||
static bool ParseNextInternal(const char*& aStart, const char* aEnd,
|
static bool ParseNextInternal(const char*& aStart, const char* aEnd,
|
||||||
nsAString* aOutDecodedName,
|
bool aShouldDecode, nsAString* aOutputName,
|
||||||
nsAString* aOutDecodedValue);
|
nsAString* aOutputValue);
|
||||||
|
|
||||||
struct Param {
|
struct Param {
|
||||||
nsString mKey;
|
nsString mKey;
|
||||||
|
@ -1155,19 +1155,20 @@ nsresult Connection::initialize(nsIFileURL* aFileURL) {
|
|||||||
bool hasKey = false;
|
bool hasKey = false;
|
||||||
bool hasDirectoryLockId = false;
|
bool hasDirectoryLockId = false;
|
||||||
|
|
||||||
MOZ_ALWAYS_TRUE(URLParams::Parse(
|
MOZ_ALWAYS_TRUE(
|
||||||
query, [&hasKey, &hasDirectoryLockId](const nsAString& aName,
|
URLParams::Parse(query, true,
|
||||||
const nsAString& aValue) {
|
[&hasKey, &hasDirectoryLockId](const nsAString& aName,
|
||||||
if (aName.EqualsLiteral("key")) {
|
const nsAString& aValue) {
|
||||||
hasKey = true;
|
if (aName.EqualsLiteral("key")) {
|
||||||
return true;
|
hasKey = true;
|
||||||
}
|
return true;
|
||||||
if (aName.EqualsLiteral("directoryLockId")) {
|
}
|
||||||
hasDirectoryLockId = true;
|
if (aName.EqualsLiteral("directoryLockId")) {
|
||||||
return true;
|
hasDirectoryLockId = true;
|
||||||
}
|
return true;
|
||||||
return true;
|
}
|
||||||
}));
|
return true;
|
||||||
|
}));
|
||||||
|
|
||||||
bool exclusive = StaticPrefs::storage_sqlite_exclusiveLock_enabled();
|
bool exclusive = StaticPrefs::storage_sqlite_exclusiveLock_enabled();
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ URLQueryStringStripper::StripForCopyOrShare(nsIURI* aURI,
|
|||||||
|
|
||||||
URLParams params;
|
URLParams params;
|
||||||
|
|
||||||
URLParams::Parse(query, [&](nsString&& name, nsString&& value) {
|
URLParams::Parse(query, true, [&](nsString&& name, nsString&& value) {
|
||||||
nsAutoString lowerCaseName;
|
nsAutoString lowerCaseName;
|
||||||
ToLowerCase(name, lowerCaseName);
|
ToLowerCase(name, lowerCaseName);
|
||||||
// Look through the global rules.
|
// Look through the global rules.
|
||||||
@ -308,7 +308,7 @@ nsresult URLQueryStringStripper::StripQueryString(nsIURI* aURI,
|
|||||||
|
|
||||||
URLParams params;
|
URLParams params;
|
||||||
|
|
||||||
URLParams::Parse(query, [&](nsString&& name, nsString&& value) {
|
URLParams::Parse(query, false, [&](nsString&& name, nsString&& value) {
|
||||||
nsAutoString lowerCaseName;
|
nsAutoString lowerCaseName;
|
||||||
|
|
||||||
ToLowerCase(name, lowerCaseName);
|
ToLowerCase(name, lowerCaseName);
|
||||||
|
@ -1135,7 +1135,7 @@ GetQueryParamFunction::OnFunctionCall(mozIStorageValueArray* aArguments,
|
|||||||
RefPtr<nsVariant> result = new nsVariant();
|
RefPtr<nsVariant> result = new nsVariant();
|
||||||
if (!queryString.IsEmpty() && !paramName.IsEmpty()) {
|
if (!queryString.IsEmpty() && !paramName.IsEmpty()) {
|
||||||
URLParams::Parse(
|
URLParams::Parse(
|
||||||
queryString,
|
queryString, true,
|
||||||
[¶mName, &result](const nsAString& aName, const nsAString& aValue) {
|
[¶mName, &result](const nsAString& aName, const nsAString& aValue) {
|
||||||
NS_ConvertUTF16toUTF8 name(aName);
|
NS_ConvertUTF16toUTF8 name(aName);
|
||||||
if (!paramName.Equals(name)) {
|
if (!paramName.Equals(name)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user