KQL removes leading zero and breaks query (#62748)
* KQL removes leading zero and breaks query * correctly parse numbers started from '.' Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
d53997742b
commit
321430ecad
|
@ -222,9 +222,8 @@ module.exports = (function() {
|
|||
if (sequence === 'true') return buildLiteralNode(true);
|
||||
if (sequence === 'false') return buildLiteralNode(false);
|
||||
if (chars.includes(wildcardSymbol)) return buildWildcardNode(sequence);
|
||||
const number = Number(sequence);
|
||||
const value = isNaN(number) ? sequence : number;
|
||||
return buildLiteralNode(value);
|
||||
const isNumberPattern = /^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$|^[.]\d{1,}$/
|
||||
return buildLiteralNode(isNumberPattern.test(sequence) ? Number(sequence) : sequence);
|
||||
},
|
||||
peg$c50 = { type: "any", description: "any character" },
|
||||
peg$c51 = "*",
|
||||
|
@ -3164,4 +3163,4 @@ module.exports = (function() {
|
|||
SyntaxError: peg$SyntaxError,
|
||||
parse: peg$parse
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -278,6 +278,33 @@ describe('kuery AST API', () => {
|
|||
expect(fromLiteralExpression('true')).toEqual(booleanTrueLiteral);
|
||||
expect(fromLiteralExpression('false')).toEqual(booleanFalseLiteral);
|
||||
expect(fromLiteralExpression('42')).toEqual(numberLiteral);
|
||||
|
||||
expect(fromLiteralExpression('.3').value).toEqual(0.3);
|
||||
expect(fromLiteralExpression('.36').value).toEqual(0.36);
|
||||
expect(fromLiteralExpression('.00001').value).toEqual(0.00001);
|
||||
expect(fromLiteralExpression('3').value).toEqual(3);
|
||||
expect(fromLiteralExpression('-4').value).toEqual(-4);
|
||||
expect(fromLiteralExpression('0').value).toEqual(0);
|
||||
expect(fromLiteralExpression('0.0').value).toEqual(0);
|
||||
expect(fromLiteralExpression('2.0').value).toEqual(2.0);
|
||||
expect(fromLiteralExpression('0.8').value).toEqual(0.8);
|
||||
expect(fromLiteralExpression('790.9').value).toEqual(790.9);
|
||||
expect(fromLiteralExpression('0.0001').value).toEqual(0.0001);
|
||||
expect(fromLiteralExpression('96565646732345').value).toEqual(96565646732345);
|
||||
|
||||
expect(fromLiteralExpression('..4').value).toEqual('..4');
|
||||
expect(fromLiteralExpression('.3text').value).toEqual('.3text');
|
||||
expect(fromLiteralExpression('text').value).toEqual('text');
|
||||
expect(fromLiteralExpression('.').value).toEqual('.');
|
||||
expect(fromLiteralExpression('-').value).toEqual('-');
|
||||
expect(fromLiteralExpression('001').value).toEqual('001');
|
||||
expect(fromLiteralExpression('00.2').value).toEqual('00.2');
|
||||
expect(fromLiteralExpression('0.0.1').value).toEqual('0.0.1');
|
||||
expect(fromLiteralExpression('3.').value).toEqual('3.');
|
||||
expect(fromLiteralExpression('--4').value).toEqual('--4');
|
||||
expect(fromLiteralExpression('-.4').value).toEqual('-.4');
|
||||
expect(fromLiteralExpression('-0').value).toEqual('-0');
|
||||
expect(fromLiteralExpression('00949').value).toEqual('00949');
|
||||
});
|
||||
|
||||
test('should allow escaping of special characters with a backslash', () => {
|
||||
|
|
|
@ -247,9 +247,8 @@ UnquotedLiteral
|
|||
if (sequence === 'true') return buildLiteralNode(true);
|
||||
if (sequence === 'false') return buildLiteralNode(false);
|
||||
if (chars.includes(wildcardSymbol)) return buildWildcardNode(sequence);
|
||||
const number = Number(sequence);
|
||||
const value = isNaN(number) ? sequence : number;
|
||||
return buildLiteralNode(value);
|
||||
const isNumberPattern = /^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$|^[.]\d{1,}$/
|
||||
return buildLiteralNode(isNumberPattern.test(sequence) ? Number(sequence) : sequence);
|
||||
}
|
||||
|
||||
UnquotedCharacter
|
||||
|
|
Loading…
Reference in a new issue