Full-width space on line before selector declaration wrongly included in selector name
sudofox opened this issue · comments
Austin Burk commented
I was debugging some issues with trying to clean some css rules from a few hundred individual css files (used in an embedded application which only supports one css file at a time). However, for some reason it wasn't removing certain rules. As it turns out, there were zero-width spaces (U+200B / UTF-8 0xE2 0x80 0x8B (e2808b)
) being incorrectly pulled into the selector. Interestingly, it also pulled the newline (0x0A) after the full-width space as well.
<?php
$data = <<<CSS
div.thing {
margin: 0 11px 0 11px;
}
CSS;
$oCssParser = new Sabberworm\CSS\Parser($data);
$oCssDocument = $oCssParser->parse();
$oCssDocument->removeDeclarationBlockBySelector("div.thing");
foreach ($oCssDocument->getAllDeclarationBlocks() as $oBlock) {
$selectorName = current($oBlock->getSelectors());
echo "'" . $selectorName . "' => " . bin2hex($selectorName) . PHP_EOL;
}
echo "'" . $oCssDocument->render() . "'";
$ php bugtest.php
'
div.thing' => e2808b0a6469762e7468696e67
'
div.thing {margin: 0 11px 0 11px;}'