From 1d1772e655f6fdb22a9657036bc0e7d6d7b4e730 Mon Sep 17 00:00:00 2001 From: HeySora Date: Mon, 26 Sep 2022 20:48:17 +0200 Subject: [PATCH 1/5] Make strSubMatch() case-insensitive --- web_src/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/utils.js b/web_src/js/utils.js index 343ee4a03bdaa..67fb050d5c495 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -66,7 +66,7 @@ export function strSubMatch(full, sub) { let i = 0, j = 0; while (i < sub.length && j < full.length) { while (j < full.length) { - if (sub[i] === full[j]) { + if (typeof sub[i] !== 'undefined' && typeof full[j] !== 'undefined' && sub[i].toLowerCase() === full[j].toLowerCase()) { if (res.length % 2 !== 0) res.push(''); res[res.length - 1] += full[j]; j++; From 1bc99897980ac1de68913075dd7f2906556f1e2f Mon Sep 17 00:00:00 2001 From: HeySora Date: Mon, 26 Sep 2022 20:49:03 +0200 Subject: [PATCH 2/5] add strSubMatch() tests for case-insentivity --- web_src/js/utils.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web_src/js/utils.test.js b/web_src/js/utils.test.js index 90fb08e8e4e03..5c17c162aff07 100644 --- a/web_src/js/utils.test.js +++ b/web_src/js/utils.test.js @@ -95,6 +95,9 @@ test('strSubMatch', () => { expect(strSubMatch('abc', 'z')).toEqual(['abc']); expect(strSubMatch('abc', 'az')).toEqual(['abc']); + expect(strSubMatch('abc', 'aC')).toEqual(['', 'a', 'b', 'c']); + expect(strSubMatch('abC', 'ac')).toEqual(['', 'a', 'b', 'C']); + expect(strSubMatch('aabbcc', 'abc')).toEqual(['', 'a', 'a', 'b', 'b', 'c', 'c']); expect(strSubMatch('the/directory', 'hedir')).toEqual(['t', 'he', '/', 'dir', 'ectory']); }); From ad4f23329e9c0f84b75ecc771535dd0998a115e1 Mon Sep 17 00:00:00 2001 From: HeySora Date: Mon, 26 Sep 2022 21:43:34 +0200 Subject: [PATCH 3/5] ?-style type checks --- web_src/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/utils.js b/web_src/js/utils.js index 67fb050d5c495..525e62c553c1f 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -66,7 +66,7 @@ export function strSubMatch(full, sub) { let i = 0, j = 0; while (i < sub.length && j < full.length) { while (j < full.length) { - if (typeof sub[i] !== 'undefined' && typeof full[j] !== 'undefined' && sub[i].toLowerCase() === full[j].toLowerCase()) { + if (sub[i]?.toLowerCase() === full[j]?.toLowerCase()) { if (res.length % 2 !== 0) res.push(''); res[res.length - 1] += full[j]; j++; From b5be178b3cb7711f820e981cd6e94be11ee1b775 Mon Sep 17 00:00:00 2001 From: HeySora Date: Mon, 26 Sep 2022 21:56:22 +0200 Subject: [PATCH 4/5] Cleanup of strSubmatch() to avoid double-loop --- web_src/js/utils.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/web_src/js/utils.js b/web_src/js/utils.js index 525e62c553c1f..bbc5e7d7658c3 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -65,18 +65,15 @@ export function strSubMatch(full, sub) { const res = ['']; let i = 0, j = 0; while (i < sub.length && j < full.length) { - while (j < full.length) { - if (sub[i]?.toLowerCase() === full[j]?.toLowerCase()) { - if (res.length % 2 !== 0) res.push(''); - res[res.length - 1] += full[j]; - j++; - i++; - } else { - if (res.length % 2 === 0) res.push(''); - res[res.length - 1] += full[j]; - j++; - break; - } + if (sub[i].toLowerCase() === full[j].toLowerCase()) { + if (res.length % 2 !== 0) res.push(''); + res[res.length - 1] += full[j]; + j++; + i++; + } else { + if (res.length % 2 === 0) res.push(''); + res[res.length - 1] += full[j]; + j++; } } if (i !== sub.length) { From 1403ea680bb656df11ecf189ee6f0d60cee1713d Mon Sep 17 00:00:00 2001 From: HeySora Date: Tue, 27 Sep 2022 10:43:12 +0200 Subject: [PATCH 5/5] Lowercase the whole string for the match --- web_src/js/utils.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web_src/js/utils.js b/web_src/js/utils.js index bbc5e7d7658c3..8e8dc01be18eb 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -64,8 +64,9 @@ export function parseIssueHref(href) { export function strSubMatch(full, sub) { const res = ['']; let i = 0, j = 0; - while (i < sub.length && j < full.length) { - if (sub[i].toLowerCase() === full[j].toLowerCase()) { + const subLower = sub.toLowerCase(), fullLower = full.toLowerCase(); + while (i < subLower.length && j < fullLower.length) { + if (subLower[i] === fullLower[j]) { if (res.length % 2 !== 0) res.push(''); res[res.length - 1] += full[j]; j++;