tbela99 / css

A CSS parser and minifier and sourcemap generator written in PHP
Other
14 stars 1 forks source link

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

Closed rinart73 closed 1 year ago

rinart73 commented 1 year ago

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. https://github.com/tbela99/css/blob/16810e7d15e312dbea157dc807249e7f21b5cf8b/src/TBela/CSS/Value.php#L1202

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