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

Side by Side Diff: chrome/browser/search_engines/template_url.cc

Issue 543077: The search terms are escaped using + or %20 for space depending on whether re... (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/search_engines/template_url.h" 5 #include "chrome/browser/search_engines/template_url.h"
6 6
7 #include "app/gfx/favicon_size.h" 7 #include "app/gfx/favicon_size.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "base/i18n/icu_string_conversions.h" 9 #include "base/i18n/icu_string_conversions.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 const std::wstring& terms, 239 const std::wstring& terms,
240 int accepted_suggestion, 240 int accepted_suggestion,
241 const std::wstring& original_query_for_suggestion) const { 241 const std::wstring& original_query_for_suggestion) const {
242 ParseIfNecessary(); 242 ParseIfNecessary();
243 if (!valid_) 243 if (!valid_)
244 return std::wstring(); 244 return std::wstring();
245 245
246 if (replacements_.empty()) 246 if (replacements_.empty())
247 return parsed_url_; 247 return parsed_url_;
248 248
249 // Determine if the search terms are in the query or before. We're escaping
250 // space as '+' in the former case and as '%20' in the latter case.
251 bool use_plus = true;
252 for (Replacements::iterator i = replacements_.begin();
253 i != replacements_.end(); ++i) {
254 if (i->type == SEARCH_TERMS) {
255 std::wstring::size_type query_start = parsed_url_.find(L'?');
256 use_plus = query_start != std::wstring::npos &&
257 (static_cast<std::wstring::size_type>(i->index) > query_start);
258 break;
259 }
260 }
261
249 // Encode the search terms so that we know the encoding. 262 // Encode the search terms so that we know the encoding.
250 const std::vector<std::string>& encodings = host.input_encodings(); 263 const std::vector<std::string>& encodings = host.input_encodings();
251 string16 encoded_terms; 264 string16 encoded_terms;
252 string16 encoded_original_query; 265 string16 encoded_original_query;
253 std::wstring input_encoding; 266 std::wstring input_encoding;
254 for (size_t i = 0; i < encodings.size(); ++i) { 267 for (size_t i = 0; i < encodings.size(); ++i) {
255 if (EscapeQueryParamValue(WideToUTF16Hack(terms), 268 if (EscapeQueryParamValue(WideToUTF16Hack(terms),
256 encodings[i].c_str(), &encoded_terms)) { 269 encodings[i].c_str(), use_plus, &encoded_terms)) {
257 if (!original_query_for_suggestion.empty()) { 270 if (!original_query_for_suggestion.empty()) {
258 EscapeQueryParamValue(WideToUTF16Hack(original_query_for_suggestion), 271 EscapeQueryParamValue(WideToUTF16Hack(original_query_for_suggestion),
259 encodings[i].c_str(), &encoded_original_query); 272 encodings[i].c_str(),
273 true,
274 &encoded_original_query);
260 } 275 }
261 input_encoding = ASCIIToWide(encodings[i]); 276 input_encoding = ASCIIToWide(encodings[i]);
262 break; 277 break;
263 } 278 }
264 } 279 }
265 if (input_encoding.empty()) { 280 if (input_encoding.empty()) {
266 encoded_terms = WideToUTF16Hack(EscapeQueryParamValueUTF8(terms)); 281 encoded_terms = WideToUTF16Hack(EscapeQueryParamValueUTF8(terms, use_plus));
267 if (!original_query_for_suggestion.empty()) { 282 if (!original_query_for_suggestion.empty()) {
268 encoded_original_query = 283 encoded_original_query =
269 WideToUTF16Hack( 284 WideToUTF16Hack(
270 EscapeQueryParamValueUTF8(original_query_for_suggestion)); 285 EscapeQueryParamValueUTF8(original_query_for_suggestion, true));
271 } 286 }
272 input_encoding = L"UTF-8"; 287 input_encoding = L"UTF-8";
273 } 288 }
274 289
275 std::wstring url = parsed_url_; 290 std::wstring url = parsed_url_;
276 291
277 // replacements_ is ordered in ascending order, as such we need to iterate 292 // replacements_ is ordered in ascending order, as such we need to iterate
278 // from the back. 293 // from the back.
279 for (Replacements::reverse_iterator i = replacements_.rbegin(); 294 for (Replacements::reverse_iterator i = replacements_.rbegin();
280 i != replacements_.rend(); ++i) { 295 i != replacements_.rend(); ++i) {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 } 597 }
583 return GURL(); 598 return GURL();
584 } 599 }
585 600
586 void TemplateURL::InvalidateCachedValues() const { 601 void TemplateURL::InvalidateCachedValues() const {
587 url_.InvalidateCachedValues(); 602 url_.InvalidateCachedValues();
588 suggestions_url_.InvalidateCachedValues(); 603 suggestions_url_.InvalidateCachedValues();
589 if (autogenerate_keyword_) 604 if (autogenerate_keyword_)
590 keyword_.clear(); 605 keyword_.clear();
591 } 606 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_util.cc ('k') | chrome/browser/search_engines/template_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698