Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to comply with TOML spec v1.0 #154

Merged
merged 6 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix float test cases
  • Loading branch information
frostming committed Dec 20, 2021
commit 2337e1a0d260a5b36b3482d287196820b4f3eff6
19 changes: 6 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,14 @@ def get_tomltest_cases():
if relpath == ".":
relpath = ""
for f in files:
bn, ext = f.rsplit(".", 1)
try:
bn, ext = f.rsplit(".", 1)
except ValueError:
bn, ext = f.rsplit("-", 1)
key = os.path.join(relpath, bn)
if key in ignored:
continue
if ext == "multi":
with open(os.path.join(root, f), "rb") as f:
for line in f:
line = line.decode("utf-8")
name = line.split("=")[0].strip()
if not name or name.startswith("#"):
continue
new_key = os.path.join(key, name)
if new_key not in rv[d]:
rv[d][new_key] = {}
rv[d][new_key]["toml"] = line
continue
if key in ignored:
continue
if d == "invalid" and relpath == "encoding":
rv["invalid_encode"][bn] = os.path.join(root, f)
Expand Down
2 changes: 1 addition & 1 deletion tests/toml-test
15 changes: 10 additions & 5 deletions tomlkit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,11 @@ def _parse_number(self, raw: str, trivia: Trivia) -> Optional[Item]:
sign = raw[0]
raw = raw[1:]

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

Expand All @@ -758,12 +759,16 @@ def _parse_number(self, raw: str, trivia: Trivia) -> Optional[Item]:
base = 16

# Underscores should be surrounded by digits
clean = re.sub(f"(?i)(?<={digits})_(?={digits})", "", raw)
clean = re.sub(f"(?i)(?<={digits})_(?={digits})", "", raw).lower()

if "_" in clean:
return

if clean.endswith("."):
if (
clean.endswith(".")
or not clean.startswith("0x")
and clean.split("e", 1)[0].endswith(".")
):
return

try:
Expand Down