Skip to content

[BUGFIX] Allow comma-separated arguments in selectors #1292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JakeQZ
Copy link
Collaborator

@JakeQZ JakeQZ commented Jun 28, 2025

Fixes #138.
Fixes #360.
Fixes #1289.

@coveralls
Copy link

coveralls commented Jun 28, 2025

Coverage Status

coverage: 58.527% (+0.6%) from 57.935%
when pulling ad21c3d on bugfix/comma
into 6dec68e on main.

@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jun 28, 2025

This is rough and ready, though fixes #1289. I have no idea why an additional fix for comment parsing seems to be required.

I expect judicious review, and that this PR needs to be split because of the curious comment-parsing bug (why is nothing ever easy?). Anyhow, we're on the road to sorting this.

@JakeQZ JakeQZ force-pushed the bugfix/comma branch 2 times, most recently from 8626ec3 to 5705132 Compare June 28, 2025 05:41
@@ -345,6 +345,10 @@ public function consumeUntil(
$start = $this->currentPosition;

while (!$this->isEnd()) {
$comment = $this->consumeComment();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should cover this with a test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a bit mysterious why the bug this is fixing suddenly reared it's head with this change. Will need investigating as a separate issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how should we proceed here? Fix that bug first and then continue here? Or merge this PR first and than fix that bug (and cover it with tests)?

I tend to prefer the first, but am not completely sure.

WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment parsing bugfix seems to be needed for this PR (though I don't yet understand why), so it would need to be done first if it really is required for this change to work.

JakeQZ added a commit that referenced this pull request Jun 28, 2025
- Assign the result of `ParserState::peek()` to a local variable, for
  efficiency;
- Use a switch statement to branch on its value, for extensibility (e.g.
  #1292);
- Don't unnecessarily test that a quote character is not escaped when not
  within a string.
oliverklee pushed a commit that referenced this pull request Jun 28, 2025
- Assign the result of `ParserState::peek()` to a local variable, for
  efficiency;
- Use a switch statement to branch on its value, for extensibility (e.g.
  #1292);
- Don't unnecessarily test that a quote character is not escaped when not
  within a string.
@oliverklee
Copy link
Collaborator

This PR now needs a rebase.

Apart from that, is it ready for a re-review, or does it need any other changes first?

@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jun 30, 2025

This PR now needs a rebase.

Apart from that, is it ready for a re-review, or does it need any other changes first?

Have rebased. The mysterious issue with comment consumption still needs to be resolved...

@oliverklee
Copy link
Collaborator

About the commit message: The Fixes #xxxx comments needs to be on a separate line each ticket ID for the auto-closing to work.

@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jul 7, 2025

About the commit message: The Fixes #xxxx comments needs to be on a separate line each ticket ID for the auto-closing to work.

It the docs are correct, they can be on the same line, but do need to be written out individually. However, I think it's more readable if they are on separate lines, given the format I originally used won't work. I've amended the original commit.

@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jul 7, 2025

The mysterious issue with comment consumption still needs to be resolved...

I've found that this arose because this PR changes consumption behaviour to consume the first character after the selector separator (,), regardless of what it is, which is a currently a mistake in this PR that needs to be addressed.

The "Number 4" comment (here) is then the next thing consumeUntil() reads.

It so happens that there is a space after the comma, which if not pre-consumed, would allow consumeUntil() to consume the comment at the end of the loop. So I think it will be possible to complete this PR without addressing the consumeUntil() bug, and construct tests which exhibit the latter.

@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jul 8, 2025

... consumeUntil() bug, and construct tests which exhibit the latter.

#1320

Also remove fix for `consumeUntil` bug, which #1320 will address.
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jul 8, 2025

I've found that this arose because this PR changes consumption behaviour to consume the first character after the selector separator (,), regardless of what it is, which is a currently a mistake in this PR that needs to be addressed.

This is now fixed.

I think the DeclarationBlock::parse method could be refactored to be broken down into separate methods, but since this a backporting candidate, I'd rather do that later.

I think it would be possible to apply the change regarding , handling as a separate pre-PR cleanup, without the fix for bracket handling. See what you think...

@JakeQZ JakeQZ requested a review from oliverklee July 8, 2025 01:46
$parserState->consume(1);
$consumedNextCharacter = true;
}
break;
}
} while (!\in_array($nextCharacter, ['{', '}'], true) || \is_string($stringWrapperCharacter));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isset($stringWrapperCharacter) and \is_string($stringWrapperCharacter) are both checking the same thing, right? If so, maybe settle on using one of the two.

@@ -110,6 +110,8 @@ Please also have a look at our

### Fixed

- Selector functions (like `:not`) with comma-separated arguments are now
parsed correclty (#1292)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
parsed correclty (#1292)
parsed correctly (#1292)

Copy link
Collaborator Author

@JakeQZ JakeQZ Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I already fixed this. Maybe I forgot to do git pull to pick up the change applied with 'Apply suggestion', and subsequently overwote it with git push -f.

$selectorParts[] = $parserState->consume(1);
}
$selectorParts[] = $parserState->consumeUntil(
['{', '}', '\'', '"', '(', ')', ','],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this easier to understand, I propose moving this array either to a class constant or a well-named local variable. WDYT?

$selectors[] = \implode('', $selectorParts);
$selectorParts = [];
$parserState->consume(1);
$consumedNextCharacter = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm mistaken, $consumedNextCharacter is never read after line 49, and hence we can remove this line and line 59 (where it is written).

@@ -58,9 +69,31 @@ public static function parse(ParserState $parserState, ?CSSList $list = null): ?
}
}
break;
case '(':
if (!isset($stringWrapperCharacter)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can convert all those to is_string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect selector splitting Selectors inside :not() not correctly parsed
4 participants