Skip to content

Commit 2d1af7a

Browse files
ali-khalilioliverklee
authored andcommitted
[BUGFIX] Handle incorrect RGB colors better (#485)
Handle incorrect inputs color which have less than 6 chars
1 parent 4a3d572 commit 2d1af7a

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1919

2020
### Fixed
2121

22+
- Fix PHP notice caused by parsing invalid color values having less than 6 characters (#485)
2223
- Fix (regression) failure to parse at-rules with strict parsing (#456)
2324

2425
## 8.5.0

src/Value/Color.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,19 @@ public static function parse(ParserState $oParserState, $bIgnoreCase = false)
5656
$oParserState->currentLine()
5757
),
5858
];
59-
} else {
59+
} elseif ($oParserState->strlen($sValue) === 6) {
6060
$aColor = [
6161
'r' => new Size(intval($sValue[0] . $sValue[1], 16), null, true, $oParserState->currentLine()),
6262
'g' => new Size(intval($sValue[2] . $sValue[3], 16), null, true, $oParserState->currentLine()),
6363
'b' => new Size(intval($sValue[4] . $sValue[5], 16), null, true, $oParserState->currentLine()),
6464
];
65+
} else {
66+
throw new UnexpectedTokenException(
67+
'Invalid hex color value',
68+
$sValue,
69+
'custom',
70+
$oParserState->currentLine()
71+
);
6572
}
6673
} else {
6774
$sColorMode = $oParserState->parseIdentifier(true);

tests/ParserTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public function colorParsing()
146146
'l' => new Size(220.0, '%', true, $oColor->getLineNo()),
147147
'a' => new Size(0000.3, null, true, $oColor->getLineNo()),
148148
], $oColor->getColor());
149+
$aColorRule = $oRuleSet->getRules('outline-color');
150+
self::assertEmpty($aColorRule);
149151
}
150152
}
151153
foreach ($oDoc->getAllValues('color') as $sColor) {

tests/fixtures/colortest.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#yours {
1010
background-color: hsl(220, 10%, 220%);
1111
background-color: hsla(220, 10%, 220%, 0.3);
12+
outline-color: #22;
1213
}
1314

1415
#variables {

0 commit comments

Comments
 (0)