镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix: reject non-ASCII digits and whitespace in numbers - #676

Open
manoj-1407 wants to merge 1 commit into
python-poetry:masterfrom
manoj-1407:reject-non-ascii-numbers
Open

manoj-1407 wants to merge 1 commit into
python-poetry:masterfrom
manoj-1407:reject-non-ascii-numbers

Conversation

@manoj-1407

Copy link
Copy Markdown

Summary

tomlkit accepts a few numbers that TOML does not allow:

parse("v = 1.٠")       # ARABIC-INDIC DIGIT ZERO
parse("v = 1\x0b")     # a vertical tab after the number

After checking the shape of the number, the parser passes it to int() and float(). 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 to tests/test_parser.py and a changelog entry.

Agent Drafting Metadata

  • Agent: Claude Code
  • Model: Claude Sonnet 5.5
  • Notes: Claude found this by running the toml-test cases against tomlkit and wrote the patch. I read the change, ran the full test suite, and checked the cases myself.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant