String literals: a raw CR is a line ending, not content - #174
Merged
Merged
Conversation
A string wrapped across two source lines drops the newline and keeps the
next line's indentation -- already the case, and already true of a `\`
continuation over CRLF. A *bare* continuation in a CRLF file was the one
path left keeping the CR, so the same string had different content
depending on which machine saved the file:
echo(len("ab <- LF file: 4, CRLF file: 5
cd"));
That is the reference's behaviour (its lexer's `\n` rule drops only the
LF; the CR falls through to `.` and is appended), but it is not a
behaviour worth reproducing: a raw CR in source is a line ending in every
real file -- CRLF on Windows, a lone CR on a pre-OSX Mac -- and a script
that wants a real CR writes `\r`. Upstream came to the same conclusion
for the `\`-continuation case in openscad/openscad@dabdc41d6.
So `unescapeStringLiteral` now drops CR wherever it already dropped LF,
which also collapses the backslash-before-CRLF special case into the
ordinary one. Net -4 lines.
BelfrySCAD#404.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JFTVMTH6yEktHDPF5csksb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported as BelfrySCAD#404 — string continuation retaining newlines. The newline half was already fixed in #150; this is the CR that was left behind.
The remaining bug
A string wrapped across two source lines drops the newline and keeps the next line's indentation. A
\continuation over CRLF already took the whole line ending. A bare continuation in a CRLF file was the one path still keeping the CR, so the same source had different content depending on which machine saved it:echo(len("ab⏎cd"));The stray CR is invisible in every echo and every exported label, which is what makes it worth fixing rather than documenting.
Why diverge from the reference
This is the reference's behaviour — its lexer's
<cond_string>\nrule only advances the line counter, so the CR falls through to.and is appended — but it isn't behaviour worth reproducing. A raw CR in source is a line ending in every real file (CRLF on Windows, a lone CR on a pre-OSX Mac), and a script that wants a real CR writes\r, which still works. Upstream reached the same conclusion for the\-continuation case in openscad/openscad@dabdc41d6 ("Fix string line continuation regression", 2026-08-10).The change
unescapeStringLiteraldrops CR wherever it already dropped LF. That also collapses the backslash-before-CRLF special case into the ordinary one, since a trailing LF is now dropped by the loop itself — net -4 lines.Verification
StringEscapes.*extended:ARawCarriageReturnStandsForItselfbecomesARawCarriageReturnIsALineEndingToo, covering CRLF, lone CR, kept indentation, and\rstill producing a real CR.tests/test_python_bindings.py: 42 passed.🤖 Generated with Claude Code
https://claude.ai/code/session_01JFTVMTH6yEktHDPF5csksb