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

Fix number lexer to avoid conflict with object indexing #2254

Merged
merged 1 commit into from
Jun 26, 2023

Conversation

itchyny
Copy link
Contributor

@itchyny itchyny commented Jan 24, 2021

This fixes #1526, also fixes #1651.
Currently jq does not correctly handle indexing like .e0. It tries to parse as numeric literal even if it does not accept it. I fixed the lexer to consider .e0 (and alike; .E1, .E-1) as object indexing, not invalid numeric literal.

 % echo '{"e0": 1, "E1": 2, "E": 3}' | jq '.e0, .E1, .E-1, .E+1'
jq: error: Invalid numeric literal at EOF at line 1, column 3 (while parsing '.e0') at <top-level>, line 1:
.e0, .E1, .E-1, .E+1
jq: error: Invalid numeric literal at EOF at line 1, column 3 (while parsing '.E1') at <top-level>, line 1:
.e0, .E1, .E-1, .E+1
jq: error: Invalid numeric literal at EOF at line 1, column 4 (while parsing '.E-1') at <top-level>, line 1:
.e0, .E1, .E-1, .E+1
jq: error: Invalid numeric literal at EOF at line 1, column 4 (while parsing '.E+1') at <top-level>, line 1:
.e0, .E1, .E-1, .E+1
jq: 4 compile errors

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 84.525% when pulling 9eec420 on itchyny:fix-number-lexer-indexing into 80052e5 on stedolan:master.

2
2
4

Copy link
Member

Choose a reason for hiding this comment

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

Nice test

@itchyny itchyny added this to the 1.7 release milestone Jun 25, 2023
@itchyny itchyny merged commit 73966c8 into jqlang:master Jun 26, 2023
@itchyny
Copy link
Contributor Author

itchyny commented Jun 26, 2023

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants