diff --git a/src/Value/Color.php b/src/Value/Color.php index 1cf00cce..746b2968 100644 --- a/src/Value/Color.php +++ b/src/Value/Color.php @@ -56,12 +56,14 @@ 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("RGB(A) HEX val", $sValue, 'literal', $oParserState->currentLine()); } } else { $sColorMode = $oParserState->parseIdentifier(true); @@ -166,7 +168,7 @@ public function render(OutputFormat $oOutputFormat) $this->aComponents['b']->getSize() ); return '#' . (($sResult[0] == $sResult[1]) && ($sResult[2] == $sResult[3]) && ($sResult[4] == $sResult[5]) - ? "$sResult[0]$sResult[2]$sResult[4]" : $sResult); + ? "$sResult[0]$sResult[2]$sResult[4]" : $sResult); } return parent::render($oOutputFormat); } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 74449ee2..96976dfe 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -554,6 +554,17 @@ public function innerColors() self::assertSame($sExpected, $oDoc->render()); } + /** + * @test + */ + public function incorrectRGBColors() + { + $oParser = new Parser(".info-img {border:1px solid #8C0000;background-color:#fffff;}"); + $sExpected = ".info-img {border: 1px solid #8c0000;}"; + $oDoc = $oParser->parse(); + self::assertSame($sExpected, $oDoc->render()); + } + /** * @test */