From e1903c096be06303cf6c3e4d445c5e5c58301d1f Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 4 May 2024 16:37:39 +0300 Subject: [PATCH] fix #2090: preserve case only in quoted tokens --- src/options/utils/search.js | 2 +- .../options/__snapshots__/search.test.js.snap | 19 +++++++++++++++---- test/options/search.test.js | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/options/utils/search.js b/src/options/utils/search.js index 5aae193e77..39b170ee65 100644 --- a/src/options/utils/search.js +++ b/src/options/utils/search.js @@ -57,7 +57,7 @@ export function createSearchRules(search) { } else if (reStr) { str = reStr; } else { - if (str === str.toLocaleLowerCase()) flags = 'i'; + if (!quoted) flags = 'i'; str = escapeStringForRegExp(str); } /** @namespace VMSearchRule */ diff --git a/test/options/__snapshots__/search.test.js.snap b/test/options/__snapshots__/search.test.js.snap index 0eeb6963ce..6a12d12f5d 100644 --- a/test/options/__snapshots__/search.test.js.snap +++ b/test/options/__snapshots__/search.test.js.snap @@ -30,6 +30,11 @@ exports[`createSearchRules 2`] = ` "re": /CaseSensitive/u, "scope": "", }, + { + "negative": false, + "re": /CaseInsensitive/iu, + "scope": "", + }, ], "tokens": [ { @@ -60,7 +65,13 @@ exports[`createSearchRules 2`] = ` "negative": false, "parsed": "CaseSensitive", "prefix": "", - "raw": "CaseSensitive", + "raw": ""CaseSensitive"", + }, + { + "negative": false, + "parsed": "CaseInsensitive", + "prefix": "", + "raw": "CaseInsensitive", }, ], } @@ -124,7 +135,7 @@ exports[`createSearchRules 4`] = ` }, { "negative": false, - "re": /hello world/iu, + "re": /hello world/u, "scope": "name", }, ], @@ -230,12 +241,12 @@ exports[`createSearchRules 7`] = ` "rules": [ { "negative": false, - "re": /#a\\\\\\.b/iu, + "re": /#a\\\\\\.b/u, "scope": "", }, { "negative": true, - "re": /#b/iu, + "re": /#b/u, "scope": "", }, ], diff --git a/test/options/search.test.js b/test/options/search.test.js index bb66381d8a..4d750c31c1 100644 --- a/test/options/search.test.js +++ b/test/options/search.test.js @@ -2,7 +2,7 @@ import { createSearchRules } from '@/options/utils/search'; test('createSearchRules', () => { expect(createSearchRules('')).toMatchSnapshot(); - expect(createSearchRules('#a #b !#c hello CaseSensitive')).toMatchSnapshot(); + expect(createSearchRules('#a #b !#c hello "CaseSensitive" CaseInsensitive')).toMatchSnapshot(); expect(createSearchRules('#a-b #b name:hello world')).toMatchSnapshot(); expect(createSearchRules('#a.b #b name:"hello world"')).toMatchSnapshot(); expect(createSearchRules('#a.b #b name+re:"hello world"')).toMatchSnapshot();