1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Desktop: #9870: Fixed command palette not properly showing non-latin-characters (#9916)

This commit is contained in:
pedr 2024-02-19 07:31:14 -03:00 committed by GitHub
parent 2aea7fcc25
commit 563b9d8f71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 6 deletions

View File

@ -421,10 +421,12 @@ class Dialog extends React.PureComponent<Props, State> {
// make list scroll to top in every search
this.makeItemIndexVisible(0);
const keywordsWithoutEmptyString = keywords?.filter(v => !!v);
this.setState({
listType: listType,
results: results,
keywords: keywords ? keywords : await this.keywords(searchQuery),
keywords: keywordsWithoutEmptyString ? keywordsWithoutEmptyString : await this.keywords(searchQuery),
selectedItemId: results.length === 0 ? null : getResultId(results[0]),
resultsInBody: resultsInBody,
commandArgs: commandArgs,

View File

@ -24,6 +24,12 @@ describe('string-utils', () => {
'dfasdf', '[', ']', { escapeHtml: true }, '[d]fas[d]f',
],
[['zzz'], 'zzz<img src=q onerror=eval("require(\'child_process\').exec(\'mate-calc\');");>', 'a', 'b', { escapeHtml: true }, 'azzzb&lt;img src=q onerror=eval(&quot;require(&apos;child_process&apos;).exec(&apos;mate-calc&apos;);&quot;);&gt;'],
[['a'], 'non-latin-chars-éão', '<span>', '</span>', { escapeHtml: true }, 'non-l<span>a</span>tin-ch<span>a</span>rs-&eacute;<span>&atilde;</span>o'],
[['o'], 'Abrir diretório de perfis > (openProfileDirectory)', '<span>', '</span>', { escapeHtml: true },
'Abrir diret<span>&oacute;</span>ri<span>o</span> de perfis &gt; (<span>o</span>penPr<span>o</span>fileDirect<span>o</span>ry)'],
[[], '<>"\'&', 'a', 'b', { escapeHtml: true }, '&lt;&gt;&quot;&apos;&amp;'],
[[], '<>"\'&', 'a', 'b', { escapeHtml: false }, '<>"\'&'],
[['a'], 'non-latin-chars-éão', '<<<', '>>>', { escapeHtml: false }, 'non-l<<<a>>>tin-ch<<<a>>>rs-é<<<ã>>>o'],
])('should surround keywords with strings (case %#)', (async (keywords, input, prefix, suffix, options, expected) => {
const actual = StringUtils.surroundKeywords(keywords, input, prefix, suffix, options);

View File

@ -235,9 +235,9 @@ interface SurroundKeywordOptions {
export function surroundKeywords(keywords: KeywordType, text: string, prefix: string, suffix: string, options: SurroundKeywordOptions|null = null) {
options = { escapeHtml: false, ...options };
text = options.escapeHtml ? htmlentities(text) : text;
if (!keywords.length) return text;
if (!keywords.length) {
return options.escapeHtml ? htmlentities(text) : text;
}
let regexString = keywords
.map(k => {
@ -251,8 +251,18 @@ export function surroundKeywords(keywords: KeywordType, text: string, prefix: st
})
.join('|');
regexString = `(${regexString})`;
const re = new RegExp(regexString, 'gi');
return text.replace(re, `${prefix}$1${suffix}`);
const keywordRegex = new RegExp(regexString, 'gi');
return text
.split(keywordRegex)
.map((textSegment) => {
const encodedText = options.escapeHtml ? htmlentities(textSegment) : textSegment;
if (keywordRegex.test(textSegment)) {
return `${prefix}${encodedText}${suffix}`;
} else {
return encodedText;
}
}).join('');
}
export function substrWithEllipsis(s: string, start: number, length: number) {