Skip to content

fix(parser): @font-face at-rule name parsing by removing trailing brace character #126

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

Merged
merged 1 commit into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/nbproject/
/vendor
/tools/vendor
/tools/*.phar
composer.lock
.cache
tests/.phpunit.result.cache
Expand Down
13 changes: 9 additions & 4 deletions src/CssLint/Tokenizer/Parser/AtRuleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ private function getAtRuleName(TokenizerContext $tokenizerContext): string
{
$content = trim($tokenizerContext->getCurrentContent());
$parts = explode(' ', trim($content), 2);
return trim(
$name = trim(
$this->removeStartingString(
$parts[0],
self::$AT_RULE_START
)
);

return $this->removeAtRuleEndingString($name);
}

private function getAtRuleValue(TokenizerContext $tokenizerContext): ?string
Expand All @@ -123,12 +125,15 @@ private function getAtRuleValue(TokenizerContext $tokenizerContext): ?string
return null;
}

$atRuleValue = $parts[1];
return $this->removeAtRuleEndingString($parts[1]);
}

private function removeAtRuleEndingString(string $content): string
{
foreach ([self::$AT_RULE_END, BlockParser::$BLOCK_START] as $endChar) {
$atRuleValue = self::removeEndingString($atRuleValue, $endChar);
$content = self::removeEndingString($content, $endChar);
}

return trim($atRuleValue);
return trim($content);
}
}
75 changes: 75 additions & 0 deletions tests/TestSuite/Tokenizer/TokenizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,81 @@ public function testTokenizeWithMultilineComments()
$this->assertTokensOrErrorsEquals($expectedTokensOrErrors, $tokensOrErrors);
}

public function testTokenizeWithAtRuleProperties()
{
// Arrange
$stream = $this->getStream("@font-face{font-family:'Open Sans';src: url('open-sans.woff2');}");

// Act
$tokensOrErrors = iterator_to_array($this->tokenizer->tokenize($stream), false);

// Assert
$expectedTokensOrErrors = [
[
'type' => 'at-rule',
'value' => [
'name' => 'font-face',
'value' => null,
'isBlock' => true,
],
'start' => [
'line' => 1,
'column' => 1,
],
'end' => [
'line' => 1,
'column' => 10,
],
],
[
'type' => 'block',
'value' => [
[
'type' => 'property',
'value' => [
'name' => 'font-family',
'value' => "'Open Sans'",

],
'start' => [
'line' => 1,
'column' => 11,
],
'end' => [
'line' => 1,
'column' => 34,
],
],
[
'type' => 'property',
'value' => [
'name' => 'src',
'value' => "url('open-sans.woff2')",
],
'start' => [
'line' => 1,
'column' => 35,
],
'end' => [
'line' => 1,
'column' => 62,
],
],
],
'start' => [
'line' => 1,
'column' => 10,
],
'end' => [
'line' => 1,
'column' => 64,
],
],
];

$this->assertTokensOrErrorsEquals($expectedTokensOrErrors, $tokensOrErrors);
}

public function testTokenizeWithAtRuleInBlock()
{
// Arrange
Expand Down