From f0280d6dd4d3add41c008fe012e7aabf78d26179 Mon Sep 17 00:00:00 2001 From: Pattara Kiatisevi Date: Thu, 21 Nov 2024 20:47:48 +0700 Subject: [PATCH] Thai tone marks and vowels at the end of the search term is wrongly removed. (#29071) Co-authored-by: sukoom pornsuksiri --- server/public/model/search_params.go | 2 +- server/public/model/search_params_test.go | 44 +++++++++++++++++++ webapp/channels/src/utils/text_formatting.tsx | 3 +- ...ext_formatting_search_highlighting.test.ts | 5 +++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/server/public/model/search_params.go b/server/public/model/search_params.go index bbb21b89dc..1b8a254e6e 100644 --- a/server/public/model/search_params.go +++ b/server/public/model/search_params.go @@ -11,7 +11,7 @@ import ( ) var searchTermPuncStart = regexp.MustCompile(`^[^\pL\d\s#"]+`) -var searchTermPuncEnd = regexp.MustCompile(`[^\pL\d\s*"]+$`) +var searchTermPuncEnd = regexp.MustCompile(`[^\pL\p{M}\d\s*"]+$`) type SearchParams struct { Terms string `json:"terms,omitempty"` diff --git a/server/public/model/search_params_test.go b/server/public/model/search_params_test.go index ed61b63edb..4e8d38b3dd 100644 --- a/server/public/model/search_params_test.go +++ b/server/public/model/search_params_test.go @@ -1011,6 +1011,50 @@ func TestParseSearchFlags2(t *testing.T) { }, }, }, + { + Name: "string end with thai upper vowel", + Input: "สวัสดี", + Words: []searchWord{ + { + value: "สวัสดี", + exclude: false, + }, + }, + Flags: []flag{}, + }, + { + Name: "string end with thai upper tone mark", + Input: "ที่นี่", + Words: []searchWord{ + { + value: "ที่นี่", + exclude: false, + }, + }, + Flags: []flag{}, + }, + { + Name: "string end with thai upper indication mark", + Input: "การันต์", + Words: []searchWord{ + { + value: "การันต์", + exclude: false, + }, + }, + Flags: []flag{}, + }, + { + Name: "string end with thai lower vowel", + Input: "กตัญญู", + Words: []searchWord{ + { + value: "กตัญญู", + exclude: false, + }, + }, + Flags: []flag{}, + }, } { t.Run(testCase.Name, func(t *testing.T) { words, flags := parseSearchFlags(splitWords(testCase.Input)) diff --git a/webapp/channels/src/utils/text_formatting.tsx b/webapp/channels/src/utils/text_formatting.tsx index ffc7fac968..7884ae20e8 100644 --- a/webapp/channels/src/utils/text_formatting.tsx +++ b/webapp/channels/src/utils/text_formatting.tsx @@ -275,9 +275,10 @@ const DEFAULT_OPTIONS: TextFormattingOptions = { * Hangul Compatibility Jamo: \u3130-\u318f * Cyrillic characters: \u0400-\u04ff, \u0500-\u052f * Additional CJK and Hangul compatibility characters: \u2de0-\u2dff +* Thai characters: \u0e00-\u0e7f **/ // eslint-disable-next-line no-misleading-character-class -export const cjkrPattern = /[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf\uac00-\ud7a3\u1100-\u11ff\u3130-\u318f\u0400-\u04ff\u0500-\u052f\u2de0-\u2dff]/; +export const cjkrPattern = /[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf\uac00-\ud7a3\u1100-\u11ff\u3130-\u318f\u0400-\u04ff\u0500-\u052f\u2de0-\u2dff\u0e00-\u0e7f]/; export function formatText( text: string, diff --git a/webapp/channels/src/utils/text_formatting_search_highlighting.test.ts b/webapp/channels/src/utils/text_formatting_search_highlighting.test.ts index 9f10fcb24e..abf81c27d9 100644 --- a/webapp/channels/src/utils/text_formatting_search_highlighting.test.ts +++ b/webapp/channels/src/utils/text_formatting_search_highlighting.test.ts @@ -94,6 +94,11 @@ describe('TextFormatting.searchHighlighting', () => { input: 'These are [words in a sentence](https://example.com).', searchMatches: ['example'], expected: '

These are words in a sentence.

', + }, { + name: 'search match thai word', + input: 'สวัสดีนี่คือการทดสอบภาษาไทย', + searchMatches: ['สวัสดี'], + expected: '

สวัสดีนี่คือการทดสอบภาษาไทย

', }]; for (const testCase of testCases) {