summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/bookmarks/bookmark_utils_unittest.cc21
-rw-r--r--chrome/browser/history/query_parser.cc15
2 files changed, 30 insertions, 6 deletions
diff --git a/chrome/browser/bookmarks/bookmark_utils_unittest.cc b/chrome/browser/bookmarks/bookmark_utils_unittest.cc
index 2192bc4..b60bd45 100644
--- a/chrome/browser/bookmarks/bookmark_utils_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_utils_unittest.cc
@@ -22,20 +22,35 @@ TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) {
std::vector<BookmarkNode*> nodes;
bookmark_utils::GetBookmarksContainingText(&model, L"foo", 100, &nodes);
- ASSERT_EQ(static_cast<size_t>(1), nodes.size());
+ ASSERT_EQ(1U, nodes.size());
EXPECT_TRUE(nodes[0] == n1);
EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(n1, L"foo"));
nodes.clear();
bookmark_utils::GetBookmarksContainingText(&model, L"cnn", 100, &nodes);
- ASSERT_EQ(static_cast<size_t>(1), nodes.size());
+ ASSERT_EQ(1U, nodes.size());
EXPECT_TRUE(nodes[0] == n2);
EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(n2, L"cnn"));
nodes.clear();
bookmark_utils::GetBookmarksContainingText(&model, L"foo bar", 100, &nodes);
- ASSERT_EQ(static_cast<size_t>(1), nodes.size());
+ ASSERT_EQ(1U, nodes.size());
EXPECT_TRUE(nodes[0] == n1);
EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(n1, L"foo bar"));
nodes.clear();
}
+
+// Makes sure if the lower case string of a bookmark title is more characters
+// than the upper case string no match positions are returned.
+TEST_F(BookmarkUtilsTest, EmptyMatchOnMultiwideLowercaseString) {
+ BookmarkModel model(NULL);
+ BookmarkNode* n1 =
+ model.AddURL(model.other_node(), 0, L"\u0130 i",
+ GURL("http://www.google.com"));
+
+ std::vector<bookmark_utils::TitleMatch> matches;
+ bookmark_utils::GetBookmarksMatchingText(&model, L"i", 100, &matches);
+ ASSERT_EQ(1U, matches.size());
+ EXPECT_TRUE(matches[0].node == n1);
+ EXPECT_TRUE(matches[0].match_positions.empty());
+}
diff --git a/chrome/browser/history/query_parser.cc b/chrome/browser/history/query_parser.cc
index cb9cf40..3f80f7f 100644
--- a/chrome/browser/history/query_parser.cc
+++ b/chrome/browser/history/query_parser.cc
@@ -301,7 +301,8 @@ bool QueryParser::DoesQueryMatch(const std::wstring& text,
return false;
std::vector<QueryWord> query_words;
- ExtractQueryWords(l10n_util::ToLower(text), &query_words);
+ std::wstring lower_text = l10n_util::ToLower(text);
+ ExtractQueryWords(lower_text, &query_words);
if (query_words.empty())
return false;
@@ -311,8 +312,16 @@ bool QueryParser::DoesQueryMatch(const std::wstring& text,
if (!query_nodes[i]->HasMatchIn(query_words, &matches))
return false;
}
- CoalseAndSortMatchPositions(&matches);
- match_positions->swap(matches);
+ if (lower_text.length() != text.length()) {
+ // The lower case string differs from the original string. The matches are
+ // meaningless.
+ // TODO(sky): we need a better way to align the positions so that we don't
+ // completely punt here.
+ match_positions->clear();
+ } else {
+ CoalseAndSortMatchPositions(&matches);
+ match_positions->swap(matches);
+ }
return true;
}