From 41f2a6f8a42a4b1135aaed05a3b17c9ea001b3e1 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Thu, 15 Jul 2021 22:57:12 +0300 Subject: [PATCH] InputText: fix search on multi-bytes UTF-8 (#7981) Also fix crashes when text is invalid UTF-8. --- frontend/ui/widget/inputtext.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index f7904edfd..313cc96c1 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -673,19 +673,19 @@ end -- if start_pos not set, starts a search from the next to cursor position -- returns first found position or 0 if not found function InputText:searchString(str, case_sensitive, start_pos) - local str_len = string.len(str) + local str_charlist = util.splitToChars(str) + local str_len = #str_charlist local char_pos, found = 0, 0 start_pos = start_pos and (start_pos - 1) or self.charpos - if not case_sensitive then - str = Utf8Proc.lowercase(str) - end for i = start_pos, #self.charlist - str_len do for j = 1, str_len do local char_txt = self.charlist[i + j] + local char_str = str_charlist[j] if not case_sensitive then - char_txt = Utf8Proc.lowercase(char_txt) + char_txt = Utf8Proc.lowercase(util.fixUtf8(char_txt, "?")) + char_str = Utf8Proc.lowercase(util.fixUtf8(char_str, "?")) end - if char_txt ~= string.sub(str, j, j) then + if char_txt ~= char_str then found = 0 break end