Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/src/components/QueryBuilderV2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ function formatSingleValueForFilter(
if (trimmed === 'true' || trimmed === 'false') {
return trimmed === 'true';
}

if (isQuoted(value)) {
return unquote(value);
}
}

// Return non-string values as-is, or string values that couldn't be converted
Expand Down
52 changes: 52 additions & 0 deletions frontend/src/utils/__tests__/queryContextUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,58 @@ describe('extractQueryPairs', () => {
]);
});

test('should test for filer expression with freeText', () => {
const input = "disconnected deployment.env not in ['mq-kafka']";
const result = extractQueryPairs(input);
expect(result).toEqual([
{
key: 'disconnected',
operator: '',
valueList: [],
valuesPosition: [],
hasNegation: false,
isMultiValue: false,
value: undefined,
position: {
keyStart: 0,
keyEnd: 11,
operatorStart: 0,
operatorEnd: 0,
negationStart: 0,
negationEnd: 0,
valueStart: undefined,
valueEnd: undefined,
},
isComplete: false,
},
{
key: 'deployment.env',
operator: 'in',
value: "['mq-kafka']",
valueList: ["'mq-kafka'"],
valuesPosition: [
{
start: 36,
end: 45,
},
],
hasNegation: true,
isMultiValue: true,
position: {
keyStart: 13,
keyEnd: 26,
operatorStart: 32,
operatorEnd: 33,
valueStart: 35,
valueEnd: 46,
negationStart: 28,
negationEnd: 30,
},
isComplete: true,
},
]);
});

test('should extract IN with numeric list inside parentheses', () => {
const input = 'id IN (1, 2, 3)';
const result = extractQueryPairs(input);
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/utils/queryContextUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,7 @@ export function extractQueryPairs(query: string): IQueryPair[] {
else if (
currentPair &&
currentPair.key &&
(isConjunctionToken(token.type) ||
(token.type === FilterQueryLexer.KEY && isQueryPairComplete(currentPair)))
(isConjunctionToken(token.type) || token.type === FilterQueryLexer.KEY)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Incomplete pairs create malformed filters with empty operators

The removal of isQueryPairComplete(currentPair) allows incomplete query pairs (free text without operators) to be returned by extractQueryPairs. However, convertExpressionToFilters processes all pairs without checking isComplete, creating filters with empty operators and values. When these filters are later converted back to expressions via convertFiltersToExpression, it produces malformed expressions like "keyname ''" (double space with empty quoted value), which could cause parsing errors or unexpected query behavior downstream.

Additional Locations (1)

Fix in CursorΒ Fix in Web

) {
queryPairs.push({
key: currentPair.key,
Expand Down
Loading