Skip to content

Write ESC as \u001b instead of the TOML 1.1-only \e escape - #641

Open
TheNetherWatcher wants to merge 1 commit into
python-poetry:masterfrom
TheNetherWatcher:fix-esc-escape-tomllib-compat
Open

TheNetherWatcher wants to merge 1 commit into
python-poetry:masterfrom
TheNetherWatcher:fix-esc-escape-tomllib-compat

Conversation

@TheNetherWatcher

Copy link
Copy Markdown

Summary

Since the TOML 1.1 update (#456), _escaped maps e to ESC, and _compact_escapes is derived from it, so dumps() now writes \x1b as \e in basic strings, multiline basic strings and quoted keys. \e is only valid in TOML 1.1, so the output can no longer be read by TOML 1.0 parsers such as the stdlib tomllib:

>>> tomllib.loads(tomlkit.dumps({"a": "x\x1by"}))
tomllib.TOMLDecodeError: Unescaped '\' in a string (at line 1, column 8)

This excludes e from the encode table only, so ESC is written as \u001b (valid in both 1.0 and 1.1), while the parser keeps accepting \e.

Tests: dumping ESC in a value, a quoted key and a multiline string gives \u001b and round-trips; the output loads with tomllib (3.11+); parsing "\e" / """\e""" still yields \x1b.

Agent Drafting Metadata

  • Agent: Claude Code
  • Model: Claude Opus 5.5
  • Notes: Agent investigated, implemented the fix and tests, and drafted this description. Full test suite (1100 tests) and pre-commit hooks pass locally.

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