Skip to content

Strip carriage returns when splitting lines - #1400

Merged
jmcphers merged 1 commit into
mainfrom
bugfix/crlf-input-boundary
Sep 4, 2026
Merged

Strip carriage returns when splitting lines#1400
jmcphers merged 1 commit into
mainfrom
bugfix/crlf-input-boundary

Conversation

@jmcphers

@jmcphers jmcphers commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

strings::lines is supposed to split text into lines and drop a trailing carriage return so CRLF input is handled, but the carriage return was never stripped. The code first checked for a trailing newline and returned early when it wasn't found. Since the function splits on newlines, no piece ever ends in a newline, so that check always returned early and the carriage return stripping below it was never reached.

The effect shows up in input boundary detection. Those lines are handed to R's parser as a character vector, and a carriage return outside a string literal is an invalid token. Complete R code then gets misclassified, and in some cases a multi-line quoted string followed by another line is reported as incomplete. On Windows with CRLF files this meant pasted code landed in the Console but never ran.

The fix drops the dead newline check and strips the carriage return directly. A new test covers CRLF input so this does not regress.

Positron already normalizes line endings before making this request, so the user-facing bug is handled there, but any other caller or a direct request with CRLF text would still hit the same mis-parse.

Fixes #1399.

@jmcphers
jmcphers requested a review from thomasp85 September 2, 2026 22:04

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jmcphers
jmcphers merged commit 37fe33a into main Sep 4, 2026
17 checks passed
@jmcphers
jmcphers deleted the bugfix/crlf-input-boundary branch September 4, 2026 18:47
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

strings::lines never strips carriage returns, so CRLF input breaks input boundaries

2 participants