Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KQL removes leading zero and breaks query #62748

Merged
merged 5 commits into from
Apr 24, 2020
Merged
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/plugins/data/common/es_query/kuery/ast/ast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/data/common/es_query/kuery/ast/kuery.peg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down