Browse Source

fix #2090: preserve case only in quoted tokens

tophf 1 year ago
parent
commit
e1903c096b

+ 1 - 1
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 */

+ 15 - 4
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": "",
     },
   ],

+ 1 - 1
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();