Skip to content

Commit 067dbd1

Browse files
authored
Merge pull request MyIntervals#194 from NitroPack/fix/escape_identifiers
2 parents bc6ec74 + 721eb4a commit 067dbd1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/Sabberworm/CSS/Parsing/ParserState.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public function parseIdentifier($bIgnoreCase = true) {
5555
}
5656
$sCharacter = null;
5757
while (($sCharacter = $this->parseCharacter(true)) !== null) {
58-
$sResult .= $sCharacter;
58+
if (preg_match('/[a-zA-Z0-9\x{00A0}-\x{FFFF}_-]/Sux', $sCharacter)) {
59+
$sResult .= $sCharacter;
60+
} else {
61+
$sResult .= '\\' . $sCharacter;
62+
}
5963
}
6064
if ($bIgnoreCase) {
6165
$sResult = $this->strtolower($sResult);

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@ function testSelectorEscapesInFile() {
466466
$this->assertSame($sExpected, $oDoc->render());
467467
}
468468

469+
function testIdentifierEscapesInFile() {
470+
$oDoc = $this->parsedStructureForFile('identifier-escapes', Settings::create()->withMultibyteSupport(true));
471+
$sExpected = 'div {font: 14px Font Awesome\ 5 Pro;font: 14px Font Awesome\} 5 Pro;font: 14px Font Awesome\; 5 Pro;f\;ont: 14px Font Awesome\; 5 Pro;}';
472+
$this->assertSame($sExpected, $oDoc->render());
473+
}
474+
469475
function testSelectorIgnoresInFile() {
470476
$oDoc = $this->parsedStructureForFile('selector-ignores', Settings::create()->withMultibyteSupport(true));
471477
$sExpected = '.some[selectors-may=\'contain-a-{\'] {}

tests/files/identifier-escapes.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
div {
2+
font: 14px Font Awesome\ 5 Pro;
3+
font: 14px Font Awesome\} 5 Pro;
4+
font: 14px Font Awesome\; 5 Pro;
5+
f\;ont: 14px Font Awesome\; 5 Pro;
6+
}

0 commit comments

Comments
 (0)