diff --git a/CHANGELOG.md b/CHANGELOG.md index 5be20aee..e6e32c3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixed +- The parser now rejects numbers with non-ASCII digits, such as `1٠` or `10`. Previously `int()` and `float()` converted them, so an invalid document parsed to a wrong value. ([#728](https://github.com/python-poetry/tomlkit/pull/728)) - Fix deleting one of several nested dotted keys inside an inline table writing invalid TOML: deleting `c` from `x = {a.b.c = 1, a.b.d = 2}` gave `x = {a.b = {}, a.b.d = 2}`, which defines `a.b` twice. The emptied part is now removed from the document, as it already was for a single-level dotted key. ([#732](https://github.com/python-poetry/tomlkit/pull/732)) ## [0.15.3] - 2026-11-24 diff --git a/tests/test_parser.py b/tests/test_parser.py index f3335e6a..265a6a53 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -351,3 +351,19 @@ def test_parser_preserves_valid_numeric_literals(raw: str, expected: float) -> N else: assert value == expected assert dumps(document) == content + + +@pytest.mark.parametrize( + "value", + [ + "1\u0660", + "0x1\u0660", + "1.\u0660", + "1e\u0661", + "1\uff10", + "1_\u0660", + ], +) +def test_parser_rejects_non_ascii_digits_in_numbers(value: str) -> None: + with pytest.raises(ParseError): + parse(f"x = {value}\n") diff --git a/tomlkit/parser.py b/tomlkit/parser.py index f2d235f0..1dcaa3ac 100644 --- a/tomlkit/parser.py +++ b/tomlkit/parser.py @@ -777,6 +777,10 @@ def _parse_number(self, raw: str, trivia: Trivia) -> Item | None: if "_" in clean: return None + # int() and float() accept any Unicode decimal digit, TOML only ASCII digits. + if not clean.isascii(): + return None + # Special float values must be lowercase in the original token. if clean in ("inf", "nan") and raw != clean: return None