Skip to content
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

Subsequent-sibling Combinator 'swallows' characters that follow it #126

Closed
rinart73 opened this issue Jul 12, 2022 · 0 comments
Closed

Subsequent-sibling Combinator 'swallows' characters that follow it #126

rinart73 opened this issue Jul 12, 2022 · 0 comments
Milestone

Comments

@rinart73
Copy link

rinart73 commented Jul 12, 2022

Input CSS:

.wp-block-gallery.has-nested-images.columns-default figure.wp-block-image:not(#individual-image):first-child:nth-last-child(2),	
.wp-block-gallery.has-nested-images.columns-default figure.wp-block-image:not(#individual-image):first-child:nth-last-child(2)~figure.wp-block-image:not(#individual-image) {	
  width: calc(50% - var(--wp--style--unstable-gallery-gap, 16px)*0.5)	
}

Code:

$input = file_get_contents('test.css');
$parser = new Parser();
$parser->setContent($input);
$stylesheet = $parser->parse();
echo $stylesheet;

Output:

.wp-block-gallery.has-nested-images.columns-default figure.wp-block-image:not(#individual-image):first-child:nth-last-child(2),
.wp-block-gallery.has-nested-images.columns-default figure.wp-block-image:not(#individual-image):first-child:nth-last-child(2)~gure.wp-block-image:not(#individual-image) {
 width: calc(50% - var(--wp--style--unstable-gallery-gap, 16px)*0.5)
}

As you can see, during the parsing the "fi" in "figure" after tilde ~ disappeared.

I tracked it to an increment in the following line. Removing increment solves the issue.

$tokens[] = (object)['type' => 'css-string', 'value' => $string[$i++]];

From what I can see that part of the switch-case handles the following situations:

  • = in the attribute context. This is handled by the following line

    $tokens[] = (object)['type' => $context === 'attribute' ? 'operator' : 'css-string', 'value' => '='];

  • ~= ^= $= in the attribute context. You're using $string[$i++] to move past the = sign to not consume it again

    $tokens[] = (object)['type' => 'operator', 'value' => $string[$i++] . '='];

  • ~ in no context which becomes part of selector. From what I can see, there is no need for increment, since you're handling only one character.

    $tokens[] = (object)['type' => 'css-string', 'value' => $string[$i++]];

@tbela99 tbela99 added this to the V0.3.6 milestone Jul 12, 2022
tbela99 added a commit that referenced this issue Jul 14, 2022
 - #125 Removing last selector causes exception
 - #126 Subsequent-sibling Combinator 'swallows' characters that follow it
 - #127 Shortening 0(unit) to 0 breaks declarations in some cases
 - #128 raising the minimum php version to 8.0
@tbela99 tbela99 closed this as completed Jul 14, 2022
tbela99 added a commit that referenced this issue Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants