Skip to content

Commit

Permalink
Fix bug in CSS tokenizer (#3906)
Browse files Browse the repository at this point in the history
... causing a rogue "closing tag" token being inserted, which leads to problematic output when a fixer tries to manipulate the token.

Includes test via the sniff which led to discovery of the issue.
  • Loading branch information
fredden authored Oct 28, 2023
1 parent 8dfb632 commit 01167c3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@
}
/* phpcs:set Squiz.WhiteSpace.SuperfluousWhitespace ignoreBlankLines false */

// /**
// * This text is in two types of comment: each line is commented out
// * individually, and the whole block is in what looks like a
// * docblock-comment. This sniff should ignore all this text as there
// * is no superfluous white-space here.
// */

Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@
float: left;
}
/* phpcs:set Squiz.WhiteSpace.SuperfluousWhitespace ignoreBlankLines false */

// /**
// * This text is in two types of comment: each line is commented out
// * individually, and the whole block is in what looks like a
// * docblock-comment. This sniff should ignore all this text as there
// * is no superfluous white-space here.
// */
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getErrorList($testFile='SuperfluousWhitespaceUnitTest.inc')
8 => 1,
9 => 1,
11 => 1,
25 => 1,
32 => 1,
];
break;
default:
Expand Down
6 changes: 5 additions & 1 deletion src/Tokenizers/CSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ public function tokenize($string)

// The first and last tokens are the open/close tags.
array_shift($commentTokens);
array_pop($commentTokens);
$closeTag = array_pop($commentTokens);

while ($closeTag['content'] !== '?'.'>') {
$closeTag = array_pop($commentTokens);
}

if ($leadingZero === true) {
$commentTokens[0]['content'] = substr($commentTokens[0]['content'], 1);
Expand Down

0 comments on commit 01167c3

Please sign in to comment.