summaryrefslogtreecommitdiffstats
path: root/chrome/browser/search_engines/template_url.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 05:51:17 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 05:51:17 +0000
commit3c75f0d3cc8f46251ab2e529229f023745ff05eb (patch)
treee6ea746a798c2fab03547aebec59f02e7d1a7d4e /chrome/browser/search_engines/template_url.cc
parent3494852e2c7da291fdd1a81922b3229790bff754 (diff)
downloadchromium_src-3c75f0d3cc8f46251ab2e529229f023745ff05eb.zip
chromium_src-3c75f0d3cc8f46251ab2e529229f023745ff05eb.tar.gz
chromium_src-3c75f0d3cc8f46251ab2e529229f023745ff05eb.tar.bz2
The search terms escaping respect forward slash: it is not escaped if the replacement preceeds ? sign.
BUG=19718 Patch by glotov@chromium.org Original review http://codereview.chromium.org/601004 TEST=Verify that slash is escaped as stated in description; example: create search engine en.wikipedia.org/%s and search it with parameters wiki/hi git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40364 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/search_engines/template_url.cc')
-rw-r--r--chrome/browser/search_engines/template_url.cc50
1 files changed, 29 insertions, 21 deletions
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 9ff827c..8432064 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -257,42 +257,50 @@ std::wstring TemplateURLRef::ReplaceSearchTerms(
// Determine if the search terms are in the query or before. We're escaping
// space as '+' in the former case and as '%20' in the latter case.
- bool use_plus = true;
+ bool is_in_query = true;
for (Replacements::iterator i = replacements_.begin();
i != replacements_.end(); ++i) {
if (i->type == SEARCH_TERMS) {
std::wstring::size_type query_start = parsed_url_.find(L'?');
- use_plus = query_start != std::wstring::npos &&
+ is_in_query = query_start != std::wstring::npos &&
(static_cast<std::wstring::size_type>(i->index) > query_start);
break;
}
}
- // Encode the search terms so that we know the encoding.
- const std::vector<std::string>& encodings = host.input_encodings();
string16 encoded_terms;
string16 encoded_original_query;
std::wstring input_encoding;
- for (size_t i = 0; i < encodings.size(); ++i) {
- if (EscapeQueryParamValue(WideToUTF16Hack(terms),
- encodings[i].c_str(), use_plus, &encoded_terms)) {
- if (!original_query_for_suggestion.empty()) {
- EscapeQueryParamValue(WideToUTF16Hack(original_query_for_suggestion),
- encodings[i].c_str(),
- true,
- &encoded_original_query);
+ // If the search terms are in query - escape them respecting the encoding.
+ if (is_in_query) {
+ // Encode the search terms so that we know the encoding.
+ const std::vector<std::string>& encodings = host.input_encodings();
+ for (size_t i = 0; i < encodings.size(); ++i) {
+ if (EscapeQueryParamValue(WideToUTF16Hack(terms),
+ encodings[i].c_str(), true,
+ &encoded_terms)) {
+ if (!original_query_for_suggestion.empty()) {
+ EscapeQueryParamValue(WideToUTF16Hack(original_query_for_suggestion),
+ encodings[i].c_str(),
+ true,
+ &encoded_original_query);
+ }
+ input_encoding = ASCIIToWide(encodings[i]);
+ break;
}
- input_encoding = ASCIIToWide(encodings[i]);
- break;
}
- }
- if (input_encoding.empty()) {
- encoded_terms = WideToUTF16Hack(EscapeQueryParamValueUTF8(terms, use_plus));
- if (!original_query_for_suggestion.empty()) {
- encoded_original_query =
- WideToUTF16Hack(
- EscapeQueryParamValueUTF8(original_query_for_suggestion, true));
+ if (input_encoding.empty()) {
+ encoded_terms = WideToUTF16Hack(
+ EscapeQueryParamValueUTF8(terms, true));
+ if (!original_query_for_suggestion.empty()) {
+ encoded_original_query =
+ WideToUTF16Hack(EscapeQueryParamValueUTF8(
+ original_query_for_suggestion, true));
+ }
+ input_encoding = L"UTF-8";
}
+ } else {
+ encoded_terms = WideToUTF16Hack(UTF8ToWide(EscapePath(WideToUTF8(terms))));
input_encoding = L"UTF-8";
}