Fix _rest_of_line regex alternation order for \r\n line endings#620
Open
bysiber wants to merge 1 commit intotheskumar:mainfrom
Open
Fix _rest_of_line regex alternation order for \r\n line endings#620bysiber wants to merge 1 commit intotheskumar:mainfrom
bysiber wants to merge 1 commit intotheskumar:mainfrom
Conversation
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.
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.
The
_rest_of_lineregex uses the alternation\r|\n|\r\nto match line endings. Since regex engines try alternations left-to-right,\ris matched before\r\never gets a chance. On Windows-style\r\nendings, this means only the\ris consumed and the\nis left unconsumed for the next parse step.The other line-ending regexes in the same file already use the correct order:
_newline\r\n|\n|\r_end_of_line\r\n|\n|\r_rest_of_line\r|\n|\r\nThis
_rest_of_lineregex is used in the error-recovery path ofparse_binding(line 170), so the impact shows up when parsing malformed lines in.envfiles with Windows line endings — the unconsumed\nbleeds into the next entry.The fix simply reorders the alternation to
\r\n|\r|\nto match the longest option first, consistent with the other regexes.