Skip to content

Commit f2be49b

Browse files
authored
Fix issue with conditional in query value (#2781)
* Add failing unit test * Add is conditional unit test * Is that really the fix? Just check for space or parthensis if midconditional. Add unit test for join * Formatting
1 parent 8e44219 commit f2be49b

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/lib/utilities/query/tokenize.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const combinedQuery =
1212
const valuesWithSpacesQuery =
1313
'`Custom Key Word`="Hello there world" AND `WorkflowId`="one and two = three" OR `WorkflowType`="example=\'one\'"';
1414
const keywordListQuery = '`CustomKeywordListField`in("Hello", "World")';
15+
const startsWithQuery = '`WorkflowType` STARTS_WITH "Hello"';
1516

1617
describe('tokenize', () => {
1718
it('should eliminate spaces', () => {
@@ -145,4 +146,28 @@ describe('tokenize', () => {
145146
'2022-04-20T18:09:49-06:00',
146147
]);
147148
});
149+
150+
it('should tokenize the startsWithQuery', () => {
151+
const query = startsWithQuery;
152+
153+
expect(tokenize(query)).toEqual(['WorkflowType', 'STARTS_WITH', 'Hello']);
154+
});
155+
156+
it('should tokenize the startsWithInQuery for values with IN conditional in them', () => {
157+
const query = '`WorkflowType` STARTS_WITH "Inspect"';
158+
159+
expect(tokenize(query)).toEqual(['WorkflowType', 'STARTS_WITH', 'Inspect']);
160+
});
161+
162+
it('should tokenize the startsWithInQuery for values with IS conditional in them', () => {
163+
const query = '`WorkflowType` STARTS_WITH "issue"';
164+
165+
expect(tokenize(query)).toEqual(['WorkflowType', 'STARTS_WITH', 'issue']);
166+
});
167+
168+
it('should tokenize the startsWithInQuery for values with JOIN conditional in them', () => {
169+
const query = '`WorkflowType` STARTS_WITH "Joiner"';
170+
171+
expect(tokenize(query)).toEqual(['WorkflowType', 'STARTS_WITH', 'Joiner']);
172+
});
148173
});

src/lib/utilities/query/tokenize.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ export const tokenize = (string: string): Tokens => {
8282
addBufferToTokens();
8383
cursor += 3;
8484
continue;
85-
} else if (isConditional(midConditional)) {
85+
} else if (
86+
isConditional(midConditional) &&
87+
(isSpace(string[cursor + 2]) || isParenthesis(string[cursor + 2]))
88+
) {
89+
// To prevent false positives like "inspect" being a "in" conditional, check for space or parenthesis after the midConditional
8690
buffer += midConditional;
8791
addBufferToTokens();
8892
cursor += 2;

0 commit comments

Comments
 (0)