Skip to content

Commit

Permalink
Merge pull request #53158 from Tony-MK/fix/52923
Browse files Browse the repository at this point in the history
fix: removing extra pair of quotes in keyword filter
  • Loading branch information
srikarparsi authored Dec 30, 2024
2 parents 78e8217 + 67eeedf commit 483d287
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libs/SearchParser/searchParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function peg$parse(input, options) {
const keywordFilter = buildFilter(
"eq",
"keyword",
keywords.map((filter) => filter.right).flat()
keywords.map((filter) => filter.right.replace(/^(['"])(.*)\1$/, '$2')).flat()
);
if (keywordFilter.right.length > 0) {
nonKeywords.push(keywordFilter);
Expand Down
100 changes: 100 additions & 0 deletions tests/unit/SearchParserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,109 @@ const tests = [
},
];

/*
* Test keywords with special characters and wrapped in quotes
*/

const keywordTests = [
{
query: '" " " "', // Multiple whitespaces wrapped in quotes
expected: {
type: 'expense',
status: 'all',
sortBy: 'date',
sortOrder: 'desc',
filters: {
operator: 'eq',
left: 'keyword',
right: [' ', ' '],
},
},
},
{
query: '"https://expensify.com" "https://new.expensify.com"',
expected: {
type: 'expense',
status: 'all',
sortBy: 'date',
sortOrder: 'desc',
filters: {
operator: 'eq',
left: 'keyword',
right: ['https://expensify.com', 'https://new.expensify.com'],
},
},
},
{
query: '""https://expensify.com"" to ""https://new.expensify.com""', // Nested quotes with a colon
expected: {
type: 'expense',
status: 'all',
sortBy: 'date',
sortOrder: 'desc',
filters: {
operator: 'eq',
left: 'keyword',
right: ['"https://expensify.com"', 'to', '"https://new.expensify.com"'],
},
},
},
{
query: '"""https://expensify.com" to "https://new.expensify.com"""', // Mismatched quotes
expected: {
type: 'expense',
status: 'all',
sortBy: 'date',
sortOrder: 'desc',
filters: {
operator: 'eq',
left: 'keyword',
right: ['""https://expensify.com', 'to', 'https://new.expensify.com""'],
},
},
},
{
query: 'date>2024-01-01 from:[email protected] "https://expensify.com" "https://new.expensify.com"',
expected: {
type: 'expense',
status: 'all',
sortBy: 'date',
sortOrder: 'desc',
filters: {
operator: 'and',
left: {
operator: 'and',
left: {
operator: 'gt',
left: 'date',
right: '2024-01-01',
},
right: {
operator: 'eq',
left: 'from',
right: '[email protected]',
},
},
right: {
operator: 'eq',
left: 'keyword',
right: ['https://expensify.com', 'https://new.expensify.com'],
},
},
},
},
];

describe('search parser', () => {
test.each(tests)(`parsing: $query`, ({query, expected}) => {
const result = searchParser.parse(query) as SearchQueryJSON;
expect(result).toEqual(expected);
});
});

describe('Testing search parser with special characters and wrapped in quotes.', () => {
test.each(keywordTests)(`parsing: $query`, ({query, expected}) => {
const result = searchParser.parse(query) as SearchQueryJSON;
expect(result).toEqual(expected);
});
});

0 comments on commit 483d287

Please sign in to comment.