Skip to content

Fix CRLF recovery after invalid dotenv statements - #722

Closed
widechaos wants to merge 1 commit into
theskumar:mainfrom
widechaos:fix-parser-crlf-recovery
Closed

widechaos wants to merge 1 commit into
theskumar:mainfrom
widechaos:fix-parser-crlf-recovery

Conversation

@widechaos

Copy link
Copy Markdown

Parsing a CRLF stream after a malformed statement consumes only the carriage return. The leftover newline is then attached to the next binding and counted again, shifting subsequent warning line numbers.

Consume CRLF as a single newline during error recovery, just as the normal parser path already does. Added a regression with two malformed lines separated by valid bindings, covering LF, CR and CRLF.

Validation: the regression fails on the original parser for CRLF; all 291 tests and the tox lint environment pass with the fix.

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI-assisted validation at c279c5918fbb on Python 3.12.14: I checked all 27 combinations of LF, CR, and CRLF separators across an invalid line, valid assignment, second invalid line, and final valid assignment. In each case the bindings retained source lines [1, 2, 3, 4], the expected error flags, and exact original text when their source slices were concatenated.

Mixed newline styles are worth preserving as a regression case as well as uniform CRLF: consuming a CR without its LF can shift every later diagnostic even when the later lines use a different ending. These checks exercise that recovery boundary directly.

@bbc2

bbc2 commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Superseded by #669.

@bbc2 bbc2 closed this Oct 28, 2026
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.

3 participants