Bug 1431924 - Do not use URLParams::ParseInput in PageThumbsProtocol::ParseProtocolURL; r=bz

MozReview-Commit-ID: 79Pg9Vlq8Bu

--HG--
extra : rebase_source : 268407fe4f206751c66c66bd378ea8ff112b816d
This commit is contained in:
Anthony Ramine 2018-01-20 09:29:55 +01:00
parent cd8167d8de
commit 7efbdaade9
3 changed files with 47 additions and 4 deletions

View File

@ -216,6 +216,47 @@ URLParams::Parse(const nsACString& aInput, ForEachIterator& aIterator)
return true;
}
class MOZ_STACK_CLASS ExtractURLParam final
: public URLParams::ForEachIterator
{
public:
explicit ExtractURLParam(const nsAString& aName, nsAString& aValue)
: mName(aName), mValue(aValue)
{}
bool URLParamsIterator(const nsAString& aName,
const nsAString& aValue) override
{
if (mName == aName) {
mValue = aValue;
return false;
}
return true;
}
private:
const nsAString& mName;
nsAString& mValue;
};
/**
* Extracts the first form-urlencoded parameter named `aName` from `aInput`.
* @param aRange The input to parse.
* @param aName The name of the parameter to extract.
* @param aValue The value of the extracted parameter, void if not found.
* @return Whether the parameter was found in the form-urlencoded.
*/
/* static */ bool
URLParams::Extract(const nsACString& aInput,
const nsAString& aName,
nsAString& aValue)
{
aValue.SetIsVoid(true);
ExtractURLParam iterator(aName, aValue);
return !URLParams::Parse(aInput, iterator);
}
class MOZ_STACK_CLASS PopulateIterator final
: public URLParams::ForEachIterator
{

View File

@ -53,6 +53,9 @@ public:
static bool
Parse(const nsACString& aInput, ForEachIterator& aIterator);
static bool
Extract(const nsACString& aInput, const nsAString& aName, nsAString& aValue);
void
ParseInput(const nsACString& aInput);

View File

@ -138,10 +138,9 @@ PageThumbsProtocol::ParseProtocolURL(nsIURI* aURI, nsString& aParsedURL)
return NS_ERROR_MALFORMED_URI;
}
URLParams params;
params.ParseInput(Substring(path, queryBegins + 1));
params.Get(NS_LITERAL_STRING("url"), aParsedURL);
URLParams::Extract(Substring(path, queryBegins + 1),
NS_LITERAL_STRING("url"),
aParsedURL);
// If there's no URL as part of the query params, there will be no thumbnail
if (aParsedURL.IsVoid()) {