From 0d2e6a6da72279fe8f66eeb3b4442b6e5f4eb67c Mon Sep 17 00:00:00 2001 From: "avayvod@google.com" Date: Fri, 15 Jan 2010 20:09:19 +0000 Subject: The search terms are escaped using + or %20 for space depending on whether replacement is in query part of the URL or not. Removed duplicate EscapeQueryParamValue functions without |use_plus| argument. BUG=24571 TEST=Verify that space is escaped as stated in description; see bug description for example with search on Wikipedia. Review URL: http://codereview.chromium.org/543077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36398 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/search_engines/template_url.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'chrome/browser/search_engines/template_url.cc') diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index 82bec3b..26da6fa 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -246,6 +246,19 @@ std::wstring TemplateURLRef::ReplaceSearchTerms( if (replacements_.empty()) return parsed_url_; + // 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; + 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 && + (static_cast(i->index) > query_start); + break; + } + } + // Encode the search terms so that we know the encoding. const std::vector& encodings = host.input_encodings(); string16 encoded_terms; @@ -253,21 +266,23 @@ std::wstring TemplateURLRef::ReplaceSearchTerms( std::wstring input_encoding; for (size_t i = 0; i < encodings.size(); ++i) { if (EscapeQueryParamValue(WideToUTF16Hack(terms), - encodings[i].c_str(), &encoded_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(), &encoded_original_query); + encodings[i].c_str(), + true, + &encoded_original_query); } input_encoding = ASCIIToWide(encodings[i]); break; } } if (input_encoding.empty()) { - encoded_terms = WideToUTF16Hack(EscapeQueryParamValueUTF8(terms)); + encoded_terms = WideToUTF16Hack(EscapeQueryParamValueUTF8(terms, use_plus)); if (!original_query_for_suggestion.empty()) { encoded_original_query = WideToUTF16Hack( - EscapeQueryParamValueUTF8(original_query_for_suggestion)); + EscapeQueryParamValueUTF8(original_query_for_suggestion, true)); } input_encoding = L"UTF-8"; } -- cgit v1.1