Repository navigation
fix: reject non-ASCII digits and whitespace in numbers - #676
Open
manoj-1407 wants to merge 1 commit into
Open
manoj-1407 wants to merge 1 commit into
manoj-1407 wants to merge 1 commit into
Conversation
int() and float() accept non-ASCII digits (e.g. '1.٠') and surrounding whitespace such as a vertical tab, which TOML does not allow. A number with either was accepted as a valid value. Reject them before the conversion. This is what the toml-test cases invalid/float/arabic-zero-*, invalid/integer/arabic-zero-* and invalid/control/linetab-number-* check.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tomlkit accepts a few numbers that TOML does not allow:
After checking the shape of the number, the parser passes it to
int()andfloat(). Both accept non-ASCII digits and surrounding whitespace, so these were parsed as valid values. The parser now rejects a number that has a non-ASCII character or a whitespace character before that conversion.The current toml-test suite has 8 invalid cases for this (
invalid/float/arabic-zero-01/03/04,invalid/integer/arabic-zero-01/02,invalid/control/linetab-number-01/02/03), which tomlkit accepted. With this change all of them are rejected, and the rest of the suite still passes. I added a parametrized test totests/test_parser.pyand a changelog entry.Agent Drafting Metadata