Skip to content

Commit

Permalink
Merge pull request #180 from bab2min/fix_length_error
Browse files Browse the repository at this point in the history
Fix length error
  • Loading branch information
bab2min authored Sep 4, 2024
2 parents 2dbd17a + 01d4d1e commit f29ae4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/KTrie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ size_t kiwi::splitByTrie(
lastSpecialEndPos * posMultiplier, specialStartPos * posMultiplier,
str.substr(nonSpaces[lastSpecialEndPos], nonSpaces[specialStartPos] - nonSpaces[lastSpecialEndPos]));
}
if (appendNewNode(out, endPosMap,
if (specialStartPos < nonSpaces.size() && appendNewNode(out, endPosMap,
specialStartPos * posMultiplier, nonSpaces.size() * posMultiplier,
U16StringView{ &str[nonSpaces[specialStartPos]], n - nonSpaces[specialStartPos] }))
{
Expand Down
13 changes: 13 additions & 0 deletions test/test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,3 +1484,16 @@ TEST(KiwiCpp, NestedSentenceSplit)
EXPECT_EQ(ranges.size(), 1);
}
}

TEST(KiwiCpp, IssueP172_LengthError)
{
std::u16string text;
text += u"\n";
for (int i = 0; i < 4000; ++i)
{
text += u"좋은채팅사이트《35141561234.wang.com》";
}
Kiwi& kiwi = reuseKiwiInstance();
auto res = kiwi.analyze(text, Match::allWithNormalizing).first;
EXPECT_GT(res.size(), 0);
}

0 comments on commit f29ae4e

Please sign in to comment.