Skip to content

Commit 01167c3

Browse files
authored
Fix bug in CSS tokenizer (#3906)
... 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.
1 parent 8dfb632 commit 01167c3

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/Standards/Squiz/Tests/WhiteSpace/SuperfluousWhitespaceUnitTest.1.css

+7
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@
2323
}
2424
/* phpcs:set Squiz.WhiteSpace.SuperfluousWhitespace ignoreBlankLines false */
2525

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

src/Standards/Squiz/Tests/WhiteSpace/SuperfluousWhitespaceUnitTest.1.css.fixed

+7
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@
2121
float: left;
2222
}
2323
/* phpcs:set Squiz.WhiteSpace.SuperfluousWhitespace ignoreBlankLines false */
24+
25+
// /**
26+
// * This text is in two types of comment: each line is commented out
27+
// * individually, and the whole block is in what looks like a
28+
// * docblock-comment. This sniff should ignore all this text as there
29+
// * is no superfluous white-space here.
30+
// */

src/Standards/Squiz/Tests/WhiteSpace/SuperfluousWhitespaceUnitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getErrorList($testFile='SuperfluousWhitespaceUnitTest.inc')
8484
8 => 1,
8585
9 => 1,
8686
11 => 1,
87-
25 => 1,
87+
32 => 1,
8888
];
8989
break;
9090
default:

src/Tokenizers/CSS.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ public function tokenize($string)
196196

197197
// The first and last tokens are the open/close tags.
198198
array_shift($commentTokens);
199-
array_pop($commentTokens);
199+
$closeTag = array_pop($commentTokens);
200+
201+
while ($closeTag['content'] !== '?'.'>') {
202+
$closeTag = array_pop($commentTokens);
203+
}
200204

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

0 commit comments

Comments
 (0)