Skip to content

Commit 1961ddb

Browse files
committed
2nd attempt to fix github-advanced-security rule violation: js/polynomial-redos (Polynomial regular expression used on uncontrolled data)
1 parent 777f432 commit 1961ddb

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/search/SearchRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export class SearchRequest {
419419
static extractQuotedStrings = (searchText: string): string[] => {
420420
// based on code generated by gemini
421421
// Regex to find tokens: quoted strings with escaped quotes, or unquoted words.
422-
const regex = /"(?:[^"\\]|\\.)+"|[\S]+/g
422+
const regex = /"[^"\\]*(?:\\.[^"\\]*)*"|[\S]+/g;
423423
// const regex = /"([^"]*)"/g;
424424
const matches = searchText.match(regex);
425425
return matches ?? [];

src/search/test_cases/search_exactPhrase.test.e2e.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ describe('Wildcard Searches', () => {
3737
// phrase with unequal quotes (edge cases)
3838
{ input: `"microsoft office`, expected: [`"microsoft`, `office`] },
3939
{ input: `"\\"abc\\"`, expected: [`"abc\\`] },
40-
{ input: `"""`, expected: [`"`] },
40+
{ input: `"""`, expected: [``, ``] },
4141
{ input: `a"b`, expected: [`a"b`] },
4242
{ input: `a\"b`, expected: [`a"b`] },
4343
// very edge cases
4444
{ input: `\"a\"b`, expected: [`a`, `b`] }, // because it's "a"b
4545
{ input: `\"a\" b`, expected: [`a`, `b`] }, // because it's "a" b
46-
{ input: `\"\"a \"b\"`, expected: [`""a`, `b`] },
46+
{ input: `\"\"a \"b\"`, expected: [``, `a`, `b`] },
4747
{ input: `"'"`, expected: [`'`] },
4848
{ input: `'"'`, expected: [`'"'`] },
4949
{ input: `'""'`, expected: [`'""'`] },
@@ -52,7 +52,7 @@ describe('Wildcard Searches', () => {
5252
];
5353

5454
testCases.forEach(({ input, expected }) => {
55-
it(`should correctly tokenize "${input}" into ${JSON.stringify(expected)}`, () => {
55+
it(`should correctly tokenize '${input}' into ${JSON.stringify(expected)}`, () => {
5656
const result = SearchRequest.tokenizeSearchText(input);
5757
expect(result).toEqual(expected);
5858
});

0 commit comments

Comments
 (0)