From fd786a784e501044be5d45db36e3fdf5ae071ccc Mon Sep 17 00:00:00 2001 From: Jo2234 <64789670+Jo2234@users.noreply.github.com> Date: Sun, 1 Mar 2026 15:19:26 +0800 Subject: [PATCH] fix: treat '#' as empty value start in parse_value When a key has an empty value followed by an inline comment, e.g.: EMPTY_VALUE= # comment The parser incorrectly included the comment as the value ('# comment') instead of returning an empty string (''). This happened because parse_value() only checked for '', '\n', '\r' as indicators of an empty value. After the '=' and trailing whitespace are consumed, a '#' character should also indicate an empty value (the rest is a comment). The fix adds '#' to the empty-value character check in parse_value(). Fixes #600 --- 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..620f0e8b 100644 --- a/src/dotenv/parser.py +++ b/src/dotenv/parser.py @@ -133,7 +133,7 @@ def parse_value(reader: Reader) -> str: elif char == '"': (value,) = reader.read_regex(_double_quoted_value) return decode_escapes(_double_quote_escapes, value) - elif char in ("", "\n", "\r"): + elif char in ("", "\n", "\r", "#"): return "" else: return parse_unquoted_value(reader)