Skip to content

Commit ec9fc7c

Browse files
committed
Resolve an infinite loop case
1 parent 83d7609 commit ec9fc7c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/Value/Value.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public static function parseValue(ParserState $oParserState, array $aListDelimit
7272
}
7373
$iStartPosition = null;
7474
while (($iStartPosition = array_search($sDelimiter, $aStack, true)) !== false) {
75+
if ($iStartPosition === 0) {
76+
break;
77+
}
7578
$iLength = 2; //Number of elements to be joined
7679
for ($i = $iStartPosition + 2; $i < count($aStack); $i += 2, ++$iLength) {
7780
if ($sDelimiter !== $aStack[$i]) {

tests/ParserTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,16 @@ public function functionArithmeticInFile()
12381238
self::assertSame($sExpected, $oDoc->render());
12391239
}
12401240

1241+
/**
1242+
* @test
1243+
*/
1244+
public function infiniteLoopInFile()
1245+
{
1246+
$oDoc = self::parsedStructureForFile('infinite-loop', Settings::create()->withMultibyteSupport(true));
1247+
$sExpected = 'div {}';
1248+
self::assertSame($sExpected, $oDoc->render());
1249+
}
1250+
12411251
public function escapedSpecialCaseTokens()
12421252
{
12431253
$oDoc = $this->parsedStructureForFile('escaped-tokens');

tests/fixtures/infinite-loop.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
div {
2+
height: ///!;
3+
}

0 commit comments

Comments
 (0)