Skip to content

Escape content appended to a String via __add__ - #612

Open
Master-Norna wants to merge 1 commit into
python-poetry:masterfrom
Master-Norna:fix/string-add-escaping
Open

Master-Norna wants to merge 1 commit into
python-poetry:masterfrom
Master-Norna:fix/string-add-escaping

Conversation

@Master-Norna

Copy link
Copy Markdown

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.
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