Skip to content

Comments

Fix _rest_of_line regex alternation order for \r\n line endings#620

Open
bysiber wants to merge 1 commit intotheskumar:mainfrom
bysiber:fix/rest-of-line-regex
Open

Fix _rest_of_line regex alternation order for \r\n line endings#620
bysiber wants to merge 1 commit intotheskumar:mainfrom
bysiber:fix/rest-of-line-regex

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

The _rest_of_line regex uses the alternation \r|\n|\r\n to match line endings. Since regex engines try alternations left-to-right, \r is matched before \r\n ever gets a chance. On Windows-style \r\n endings, this means only the \r is consumed and the \n is left unconsumed for the next parse step.

The other line-ending regexes in the same file already use the correct order:

Regex Pattern Correct?
_newline \r\n|\n|\r
_end_of_line \r\n|\n|\r
_rest_of_line \r|\n|\r\n

This _rest_of_line regex is used in the error-recovery path of parse_binding (line 170), so the impact shows up when parsing malformed lines in .env files with Windows line endings — the unconsumed \n bleeds into the next entry.

The fix simply reorders the alternation to \r\n|\r|\n to match the longest option first, consistent with the other regexes.

The _rest_of_line regex uses the alternation \r|\n|\r\n to match
line endings. Since regex alternation tries options left-to-right,
\r matches before \r\n gets a chance, leaving the \n unconsumed
on Windows-style line endings.

The other line-ending regexes in the same file (_newline, _end_of_line)
already use the correct order \r\n|\n|\r. This brings _rest_of_line
in line with them.
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