fix: treat inline comment as empty value when key= is followed by # comment#624
Open
Jo2234 wants to merge 1 commit intotheskumar:mainfrom
Open
fix: treat inline comment as empty value when key= is followed by # comment#624Jo2234 wants to merge 1 commit intotheskumar:mainfrom
Jo2234 wants to merge 1 commit intotheskumar:mainfrom
Conversation
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 theskumar#600
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.
Summary
Fix inline comment being included as the value when a key has an empty value.
Problem
Root cause
In
parse_value(), after the=sign and trailing whitespace are consumed by_equal_sign, the next character is checked:When the value is
KEY= # comment, after=is consumed, the next char is#. Since#isn't in the check, it falls through toparse_unquoted_value(), which captures# commentas the value. The regex\s+#.*inparse_unquoted_valuecan't strip it because the#is at the start — there's no whitespace before it.Fix
Adding
#to the empty-value check ensures that when the value position starts with#, it's recognized as an inline comment and the value is returned as empty. The comment itself is then properly consumed byreader.read_regex(_comment)inparse_binding().Fixes #600