Skip to content

Escape content appended to a String via __add__ - #612

Merged
frostming merged 1 commit into
python-poetry:masterfrom
Master-Norna:fix/string-add-escaping
Sep 30, 2026
Merged

frostming merged 1 commit into
python-poetry:masterfrom
Master-Norna:fix/string-add-escaping

Conversation

@Master-Norna

Copy link
Copy Markdown
Contributor

Summary

String.__add__ spliced the appended text into the raw literal without escaping it, so appending a quote or backslash to a basic string produced a literal that is not valid TOML - including to this library's own parser:

i = item("foo")
i += '"'
i.as_string()   # before: '"foo""'  (unparseable)
                # after:  '"foo\""'

Escape the appended plain text with the string type's escape sequences (a String operand keeps contributing its already-escaped raw form), mirroring what from_raw already does. This is the same class of bug as #231, which fixed the literal round-trip but not __add__.

Agent Drafting Metadata

  • Agent: Claude (Anthropic)
  • Model: Claude Opus
  • Notes: Agent assisted with investigation and drafting; the fix, tests and verification were reviewed by the submitter. Full suite passes (1059 passed).

String.__add__ spliced the appended text into the raw literal without escaping it, so appending a quote or backslash to a basic string produced a literal that is not valid TOML - including to this library's own parser. Escape the appended plain text with the string type's escape sequences (a String operand keeps contributing its already-escaped raw form), mirroring what from_raw already does.
@frostming
frostming merged commit 61941de into python-poetry:master Sep 30, 2026
25 checks passed
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