Properly handle parent selectors with whitespace #4
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
parent-selector-rematches only a single&or&followed bynon-whitespace characters (
\S). Because of this, it doesn't recognizei.e. combinator selectors that include whitespace.
This issue originates from
noprompt@d9248e4#diff-849a8061f274bbe17201c9450e913c145c6fd6945f89403ab7dc49fa98344ea3
where
parent-selector-rewas changed from#"^&.+|^&$"to#"^&(?:\S+)?$". The old regex did allow whitespaces.The commit message doesn't tell why the regex was changed. The only
reason I could come up is that since the parent selecter regex is used
to extract the reference, it was changed to not match selectors where
the reference part is whitespace only i.e.
"& "(single ampersandfollowed by space).
Example: calling
extract-referencewith the old regex:Example: calling
extract-referencewith the new regex:I think it makes sense that
extract-referencedoes NOT returnwhitespace-only strings. It feels logical that
nilis returned ifthere really isn't reference part.
However, if
extract-referencereturnsnil, it signifies to thecaller that this is not a parent selector, which is incorrect in case of
selector like
["a" "& "]. It would make sense to decouple the tworesponsibilities, checking if the selector is a parent selector and
extracting the reference part
This commit makes following changes:
parent-selector?predicate to check if the selector is aparent selector
extract-referenceso that it returnsnilfor selectors withwhitespace only reference.
Fixes: