Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: chrome/browser/search_engines/template_url.cc

Issue 555012: Removed restriction for {} so that javascript blocks can be used in the url.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search_engines/template_url.cc
===================================================================
--- chrome/browser/search_engines/template_url.cc (revision 36625)
+++ chrome/browser/search_engines/template_url.cc (working copy)
@@ -97,6 +97,7 @@
length--;
}
std::wstring parameter(url->substr(start + 1, length));
+ std::wstring full_parameter(url->substr(start, end - start + 1));
// Remove the parameter from the string.
url->erase(start, end - start + 1);
if (parameter == kSearchTermsParameter) {
@@ -137,9 +138,9 @@
} else if (parameter == kGoogleUnescapedSearchTermsParameter) {
replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS,
static_cast<int>(start)));
- } else if (!optional) {
- // Unknown required parameter. No idea what to replace this with,
- // so fail.
+ } else {
+ // It can be some garbage but can also be a javascript block. Put it back.
+ url->insert(start, full_parameter);
return false;
}
return true;
@@ -153,14 +154,22 @@
for (size_t last = 0; last != std::string::npos; ) {
last = parsed_url.find(kStartParameter, last);
if (last != std::string::npos) {
- size_t endTemplate = parsed_url.find(kEndParameter, last);
- if (endTemplate != std::string::npos) {
- if (!ParseParameter(last, endTemplate, &parsed_url, replacements)) {
- // Not a valid parameter, return.
- return std::wstring();
+ size_t template_end = parsed_url.find(kEndParameter, last);
+ if (template_end != std::string::npos) {
+ // Since we allow Javascript in the URL, {} pairs could be nested. Match
+ // only leaf pairs with supported parameters.
+ size_t next_template_start = parsed_url.find(kStartParameter, last + 1);
+ if (next_template_start == std::string::npos ||
+ next_template_start > template_end) {
+ // If successful, ParseParameter erases from the string as such no
+ // need to update |last|. If failed, move |last| to the end of pair.
+ if (!ParseParameter(last, template_end, &parsed_url, replacements)) {
+ // |template_end| + 1 may be beyond the end of the string.
+ last = template_end;
+ }
+ } else {
+ last = next_template_start;
}
- // ParseParamter erases from the string, as such we don't need
- // to update last.
} else {
// Open brace without a closing brace, return.
return std::wstring();
« no previous file with comments | « chrome/browser/search_engines/template_url.h ('k') | chrome/browser/search_engines/template_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698