Skip to content

Commit

Permalink
fix violentmonkey#2090: preserve case only in quoted tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed May 4, 2024
1 parent 3a41732 commit e1903c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/options/utils/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
19 changes: 15 additions & 4 deletions test/options/__snapshots__/search.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ exports[`createSearchRules 2`] = `
"re": /CaseSensitive/u,
"scope": "",
},
{
"negative": false,
"re": /CaseInsensitive/iu,
"scope": "",
},
],
"tokens": [
{
Expand Down Expand Up @@ -60,7 +65,13 @@ exports[`createSearchRules 2`] = `
"negative": false,
"parsed": "CaseSensitive",
"prefix": "",
"raw": "CaseSensitive",
"raw": ""CaseSensitive"",
},
{
"negative": false,
"parsed": "CaseInsensitive",
"prefix": "",
"raw": "CaseInsensitive",
},
],
}
Expand Down Expand Up @@ -124,7 +135,7 @@ exports[`createSearchRules 4`] = `
},
{
"negative": false,
"re": /hello world/iu,
"re": /hello world/u,
"scope": "name",
},
],
Expand Down Expand Up @@ -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": "",
},
],
Expand Down
2 changes: 1 addition & 1 deletion test/options/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e1903c0

Please sign in to comment.