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

@manoj-1407 manoj-1407 commented Oct 22, 2026 •

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-Assisted Development and Validation

  • Agent: Claude Code
  • Model: Claude Sonnet 5.5
  • Notes: The agent identified the issue and drafted the patch. I reviewed the resulting changes, rebased the branch onto the latest master, resolved the CHANGELOG conflict, and verified the implementation locally.

Local Validation

  • Command: python -m pytest -q --ignore=tests/test_toml_tests.py
  • Result: 812 passed in 4.73 seconds.
  • The toml-test submodule suite was excluded from this local run.

@Giacomo117 Giacomo117 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey, thanks for this! I merged it locally with today's master and the only conflict is in CHANGELOG.md.

I tried x = <number> with a bunch of inputs: Arabic-Indic digits (٠, ١) in ints, hex, floats and exponents, the fullwidth zero 0, and a vertical tab or form feed right after the number. They all get rejected now. 10, 1.5 and 0xff still parse fine, and the full pytest suite passes (1492 tests).

The red ubuntu-latest / 3.9 job isn't related to this PR. It fails while installing Python, before any test runs: ubuntu-latest is now Ubuntu 26.04, which doesn't have Python 3.9.

So I think the only thing left is updating the branch with master and fixing the CHANGELOG conflict.

Small side note, not blocking: the toml-test cases mentioned in the description aren't in the toml-test version tomlkit uses, so CI doesn't actually run them. The test you added covers the same kind of input anyway.

@Giacomo117 Giacomo117 mentioned this pull request Nov 30, 2026
1 task done
@manoj-1407 manoj-1407 closed this Dec 2, 2026
@manoj-1407
manoj-1407 force-pushed the reject-non-ascii-numbers branch from 21e9323 to 3cdcbde Compare December 2, 2026 04:59
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.
@manoj-1407 manoj-1407 reopened this Dec 2, 2026
@manoj-1407

manoj-1407 commented Dec 2, 2026 •

Copy link
Copy Markdown
Author

@Giacomo117 Thanks for the review !

i've rebased the branch onto the latest master and resolved the CHANGELOG conflict. the updated commit is pushed.

i also ran the local test suite again: 812 passed. i've kept the existing implementation and parametrized tests.

also, the PR seems to have been closed accidentally while i was updating the branch. i'm not sure what triggered it, but i've reopened it now.

the CI checks are passing now as well (25 successful). only the Human Attestation check is still pending and waiting for my attestation.

Thanks for clarifying the Python 3.9 CI issue as well !

@human-attestation

Copy link
Copy Markdown

✅ Human Attestation: @manoj-1407 attested this PR at commit cee99e6 (2026-12-02T05:17:54.820Z).

I have read and understood all agent-written code in this PR. / 我已阅读并理解此 PR 中 Agent 编写的全部代码。

Later pushes to this PR stay attested. Attestation page

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.

2 participants