Commit 9d4dfdb9 authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Commander: empty string needle should not match anything

We do sometimes want to return results for an empty string, but that
decision should be made at a higher level than the fuzzy finder.

Bug: 1014639
Change-Id: I99c4a4ef37e9a58bd7154af0a37e66e675c188fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518209
Commit-Queue: Avi Drissman <avi@chromium.org>
Auto-Submit: Leonard Grey <lgrey@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823777}
parent 19f88605
...@@ -141,6 +141,8 @@ namespace commander { ...@@ -141,6 +141,8 @@ namespace commander {
double FuzzyFind(const base::string16& needle, double FuzzyFind(const base::string16& needle,
const base::string16& haystack, const base::string16& haystack,
std::vector<gfx::Range>* matched_ranges) { std::vector<gfx::Range>* matched_ranges) {
if (needle.size() == 0)
return 0;
DCHECK(needle == base::i18n::FoldCase(needle)); DCHECK(needle == base::i18n::FoldCase(needle));
matched_ranges->clear(); matched_ranges->clear();
const base::string16& folded = base::i18n::FoldCase(haystack); const base::string16& folded = base::i18n::FoldCase(haystack);
......
...@@ -102,4 +102,12 @@ TEST(CommanderFuzzyFinder, Noncontiguous) { ...@@ -102,4 +102,12 @@ TEST(CommanderFuzzyFinder, Noncontiguous) {
EXPECT_EQ(ranges, EXPECT_EQ(ranges,
std::vector<gfx::Range>({{0, 1}, {6, 7}, {13, 14}, {19, 20}})); std::vector<gfx::Range>({{0, 1}, {6, 7}, {13, 14}, {19, 20}}));
} }
TEST(CommanderFuzzyFinder, EmptyStringDoesNotMatch) {
std::vector<gfx::Range> ranges;
EXPECT_EQ(0, FuzzyFind(base::ASCIIToUTF16(""), base::ASCIIToUTF16("orange"),
&ranges));
EXPECT_TRUE(ranges.empty());
}
} // namespace commander } // namespace commander
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment