Fix: Make exists in small case recognise as valid non value op (#9989)

* fix: make exists in small case recognise as valid non value op

* fix: lint fix
This commit is contained in:
Aditya Singh
2026-01-13 16:26:38 +05:30
committed by GitHub
parent b4282be3ac
commit 2719c9b6a7
3 changed files with 29 additions and 12 deletions

View File

@@ -380,6 +380,23 @@ describe('extractQueryPairs', () => {
consoleSpy.mockRestore();
});
test('should treat lowercase exists as non-value operator', () => {
const input = 'body exists service.name contains "test"';
const result = extractQueryPairs(input);
expect(result).toHaveLength(2);
expect(result[0].key).toBe('body');
expect(result[0].operator).toBe('exists');
expect(result[0].value).toBeUndefined();
expect(result[0].valuesPosition).toEqual([]);
expect(result[0].isComplete).toBe(false);
expect(result[1].key).toBe('service.name');
expect(result[1].operator).toBe('contains');
expect(result[1].value).toBe('"test"');
expect(result[1].valuesPosition).toEqual([]);
expect(result[1].isComplete).toBe(true);
});
});
describe('createContext', () => {

View File

@@ -10,12 +10,12 @@ import {
isFunctionToken,
isKeyToken,
isMultiValueOperator,
isNonValueOperator,
isNonValueOperatorToken,
isOperatorToken,
isQueryPairComplete,
isValueToken,
} from './tokenUtils';
import { NON_VALUE_OPERATORS } from 'constants/antlrQueryConstants';
// Function to create a context object
export function createContext(
@@ -1319,7 +1319,7 @@ export function extractQueryPairs(query: string): IQueryPair[] {
currentPair &&
currentPair.key &&
currentPair.operator &&
!NON_VALUE_OPERATORS.includes(currentPair.operator) &&
!isNonValueOperator(currentPair.operator) &&
!currentPair.value
) {
currentPair.value = token.text;

View File

@@ -87,16 +87,6 @@ export function isWrappedUnderQuotes(token: string): boolean {
);
}
export function isQueryPairComplete(queryPair: Partial<IQueryPair>): boolean {
if (!queryPair) return false;
// A complete query pair must have a key, an operator, and a value (or EXISTS operator)
if (queryPair.operator && NON_VALUE_OPERATORS.includes(queryPair.operator)) {
return !!queryPair.key && !!queryPair.operator;
}
// For other operators, we need a value as well
return Boolean(queryPair.key && queryPair.operator && queryPair.value);
}
export function isFunctionOperator(operator: string): boolean {
const functionOperators = Object.values(QUERY_BUILDER_FUNCTIONS);
@@ -134,3 +124,13 @@ export function isNonValueOperator(operator: string): boolean {
}
return false;
}
export function isQueryPairComplete(queryPair: Partial<IQueryPair>): boolean {
if (!queryPair) return false;
// A complete query pair must have a key, an operator, and a value (or EXISTS operator)
if (queryPair.operator && isNonValueOperator(queryPair.operator)) {
return !!queryPair.key && !!queryPair.operator;
}
// For other operators, we need a value as well
return Boolean(queryPair.key && queryPair.operator && queryPair.value);
}