From 5d6697baeb9d6432c8a37fcccb9c57eb1cf7c3da Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 15:22:33 +0300 Subject: [PATCH] Fix _rest_of_line regex alternation order for \r\n line endings 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. --- src/dotenv/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotenv/parser.py b/src/dotenv/parser.py index eb100b47..8a4b0a86 100644 --- a/src/dotenv/parser.py +++ b/src/dotenv/parser.py @@ -27,7 +27,7 @@ def make_regex(string: str, extra_flags: int = 0) -> Pattern[str]: _unquoted_value = make_regex(r"([^\r\n]*)") _comment = make_regex(r"(?:[^\S\r\n]*#[^\r\n]*)?") _end_of_line = make_regex(r"[^\S\r\n]*(?:\r\n|\n|\r|$)") -_rest_of_line = make_regex(r"[^\r\n]*(?:\r|\n|\r\n)?") +_rest_of_line = make_regex(r"[^\r\n]*(?:\r\n|\r|\n)?") _double_quote_escapes = make_regex(r"\\[\\'\"abfnrtv]") _single_quote_escapes = make_regex(r"\\[\\']")