Skip to content

Handle CRLF invalid lines in parser recovery - #669

Merged
bbc2 merged 2 commits into
theskumar:mainfrom
CodingFeng101:codex/preserve-cr-newline
Oct 28, 2026
Merged

bbc2 merged 2 commits into
theskumar:mainfrom
CodingFeng101:codex/preserve-cr-newline

Conversation

@CodingFeng101

Copy link
Copy Markdown
Contributor

What changed

This updates the parser recovery regex for invalid lines so CRLF is consumed as one newline sequence, matching the parser's other newline handling.

Why

When an invalid .env line used CRLF line endings, _rest_of_line matched \r before \r\n. That left the \n behind for the next parse iteration, so recovery could produce an extra blank binding before the following valid line.

Validation

  • PYTHONPATH=src python -m pytest tests\test_parser.py::test_parse_stream -q
  • PYTHONPATH=src python -m pytest tests\test_parser.py -q
  • python -m ruff check src\dotenv\parser.py tests\test_parser.py
  • git diff --check

@bbc2
bbc2 force-pushed the codex/preserve-cr-newline branch from 9392b5b to 7123417 Compare October 28, 2026 14:10
@bbc2

bbc2 commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks, I just added a test inspired by #722.

@bbc2
bbc2 merged commit bad5771 into theskumar:main Oct 28, 2026
9 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