diff --git a/CHANGELOG.md b/CHANGELOG.md index 60e1e140..97c3bfe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed +- Fix PHP notice caused by parsing invalid color values having less than 6 charachters (#485) - Fix (regression) failure to parse at-rules with strict parsing (#456) ## 8.5.0 diff --git a/src/Value/Color.php b/src/Value/Color.php index 1cf00cce..5daad412 100644 --- a/src/Value/Color.php +++ b/src/Value/Color.php @@ -56,12 +56,19 @@ public static function parse(ParserState $oParserState, $bIgnoreCase = false) $oParserState->currentLine() ), ]; - } else { + } elseif ($oParserState->strlen($sValue) === 6) { $aColor = [ 'r' => new Size(intval($sValue[0] . $sValue[1], 16), null, true, $oParserState->currentLine()), 'g' => new Size(intval($sValue[2] . $sValue[3], 16), null, true, $oParserState->currentLine()), 'b' => new Size(intval($sValue[4] . $sValue[5], 16), null, true, $oParserState->currentLine()), ]; + } else { + throw new UnexpectedTokenException( + 'Invalid hex color value', + $sValue, + 'custom', + $oParserState->currentLine() + ); } } else { $sColorMode = $oParserState->parseIdentifier(true); diff --git a/tests/ParserTest.php b/tests/ParserTest.php index c5ddeb44..a48ac0e7 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -146,6 +146,8 @@ public function colorParsing() 'l' => new Size(220.0, '%', true, $oColor->getLineNo()), 'a' => new Size(0000.3, null, true, $oColor->getLineNo()), ], $oColor->getColor()); + $aColorRule = $oRuleSet->getRules('outline-color'); + self::assertEmpty($aColorRule); } } foreach ($oDoc->getAllValues('color') as $sColor) { diff --git a/tests/fixtures/colortest.css b/tests/fixtures/colortest.css index 1c89cf41..f834aa77 100644 --- a/tests/fixtures/colortest.css +++ b/tests/fixtures/colortest.css @@ -9,6 +9,7 @@ #yours { background-color: hsl(220, 10%, 220%); background-color: hsla(220, 10%, 220%, 0.3); + outline-color: #22; } #variables {