Commit d0cba2bc authored by tby's avatar tby Committed by Commit Bot

Fix off-by-one in TokenizedString

Strings of size 1 don't have their single token picked up by
TokenizeWords, which is causing a crash in the LauncherSearchProvider.

Bug: 1140380
Change-Id: Ifb2815a1e9da79ffc0b51671d30ca87418e3170e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515425
Commit-Queue: Tony Yeoman <tby@chromium.org>
Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823763}
parent 5bd1d1e4
......@@ -98,7 +98,7 @@ void TokenizedString::TokenizeWords() {
}
// Generate the last token.
if (end - start > 1) {
if (end - start >= 1) {
tokens_.emplace_back(base::i18n::ToLower(text_.substr(start, end - start)));
mappings_.emplace_back(start, end);
}
......
......@@ -38,6 +38,13 @@ TEST(TokenizedStringTest, Empty) {
}
TEST(TokenizedStringTest, Basic) {
{
base::string16 text(base::UTF8ToUTF16("a"));
TokenizedString tokens(text);
EXPECT_EQ(base::UTF8ToUTF16("a{0,1}"), GetContent(tokens));
TokenizedString token_words(text, TokenizedString::Mode::kWords);
EXPECT_EQ(base::UTF8ToUTF16("a{0,1}"), GetContent(token_words));
}
{
base::string16 text(base::UTF8ToUTF16("ScratchPad"));
TokenizedString tokens(text);
......
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