OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/template_url.h" | 5 #include "components/search_engines/template_url.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 } else { | 704 } else { |
705 // Open brace without a closing brace, return. | 705 // Open brace without a closing brace, return. |
706 return std::string(); | 706 return std::string(); |
707 } | 707 } |
708 } | 708 } |
709 } | 709 } |
710 | 710 |
711 // Handles the post parameters. | 711 // Handles the post parameters. |
712 const std::string& post_params_string = GetPostParamsString(); | 712 const std::string& post_params_string = GetPostParamsString(); |
713 if (!post_params_string.empty()) { | 713 if (!post_params_string.empty()) { |
714 typedef std::vector<std::string> Strings; | 714 for (const base::StringPiece& cur : base::SplitStringPiece( |
715 Strings param_list; | 715 post_params_string, ",", |
716 base::SplitString(post_params_string, ',', ¶m_list); | 716 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
717 | |
718 for (Strings::const_iterator iterator = param_list.begin(); | |
719 iterator != param_list.end(); ++iterator) { | |
720 Strings parts; | |
721 // The '=' delimiter is required and the name must be not empty. | 717 // The '=' delimiter is required and the name must be not empty. |
722 base::SplitString(*iterator, '=', &parts); | 718 std::vector<std::string> parts = base::SplitString( |
| 719 cur, "=", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
723 if ((parts.size() != 2U) || parts[0].empty()) | 720 if ((parts.size() != 2U) || parts[0].empty()) |
724 return std::string(); | 721 return std::string(); |
725 | 722 |
726 std::string& value = parts[1]; | 723 std::string& value = parts[1]; |
727 size_t replacements_size = replacements->size(); | 724 size_t replacements_size = replacements->size(); |
728 if (IsTemplateParameterString(value)) | 725 if (IsTemplateParameterString(value)) |
729 ParseParameter(0, value.length() - 1, &value, replacements); | 726 ParseParameter(0, value.length() - 1, &value, replacements); |
730 PostParam param = { parts[0], value }; | 727 PostParam param = { parts[0], value }; |
731 post_params->push_back(param); | 728 post_params->push_back(param); |
732 // If there was a replacement added, points its index to last added | 729 // If there was a replacement added, points its index to last added |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 // patterns. This means that given patterns | 1513 // patterns. This means that given patterns |
1517 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1514 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1518 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1515 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1519 // return false. This is important for at least Google, where such URLs | 1516 // return false. This is important for at least Google, where such URLs |
1520 // are invalid. | 1517 // are invalid. |
1521 return !search_terms->empty(); | 1518 return !search_terms->empty(); |
1522 } | 1519 } |
1523 } | 1520 } |
1524 return false; | 1521 return false; |
1525 } | 1522 } |
OLD | NEW |