Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from tomlkit.exceptions import InvalidUnicodeValueError
from tomlkit.exceptions import ParseError
from tomlkit.exceptions import UnexpectedCharError
from tomlkit.items import Float
from tomlkit.items import Integer
from tomlkit.items import StringType
from tomlkit.parser import Parser
Expand Down Expand Up @@ -235,3 +236,13 @@ def test_parser_rejects_overlong_decimal_integer() -> None:
# the value just under the limit is still a normal integer
value = Parser("a = " + "9" * 4300).parse()["a"]
assert isinstance(value, Integer)


def test_parser_accepts_uppercase_exponent_after_leading_zero() -> None:
# Both "e" and "E" are valid exponent markers. A leading-zero mantissa was
# only exempted from the "no leading zeros" rule for lowercase "0e", so
# "0E2" and its signed forms were wrongly rejected as an invalid number.
for raw in ("0E2", "0E+2", "0E-2", "+0E2", "-0E2"):
value = Parser(f"a = {raw}").parse()["a"]
assert isinstance(value, Float)
assert value == float(raw)
5 changes: 4 additions & 1 deletion tomlkit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,10 @@ def _parse_number(self, raw: str, trivia: Trivia) -> Item | None:
raw = raw[1:]

if len(raw) > 1 and (
(raw.startswith("0") and not raw.startswith(("0.", "0o", "0x", "0b", "0e")))
(
raw.startswith("0")
and not raw.startswith(("0.", "0o", "0x", "0b", "0e", "0E"))
)
or (sign and raw.startswith("."))
):
return None
Expand Down