Skip to content

Commit 1ecfb80

Browse files
committed
Handle scientific notation when parsing sizes
1 parent a80a97d commit 1ecfb80

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/Sabberworm/CSS/Value/Size.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal
2828
if ($oParserState->comes('-')) {
2929
$sSize .= $oParserState->consume('-');
3030
}
31-
while (is_numeric($oParserState->peek()) || $oParserState->comes('.')) {
31+
while (is_numeric($oParserState->peek()) || $oParserState->comes('.') || $oParserState->comes('e+', true) || $oParserState->comes('e-', true)) {
3232
if ($oParserState->comes('.')) {
3333
$sSize .= $oParserState->consume('.');
34+
} else if ($oParserState->comes('e', true)) {
35+
$sSize .= $oParserState->consume(2);
3436
} else {
3537
$sSize .= $oParserState->consume(1);
3638
}

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,12 @@ function testLargeSizeValuesInFile() {
761761
$this->assertSame($sExpected, $oDoc->render());
762762
}
763763

764+
function testScientificNotationSizeValuesInFile() {
765+
$oDoc = $this->parsedStructureForFile('scientific-notation-numbers', Settings::create()->withMultibyteSupport(false));
766+
$sExpected = 'body {background-color: rgba(62,174,151,3041820656523200167936);z-index: .030418206565232;}';
767+
$this->assertSame($sExpected, $oDoc->render());
768+
}
769+
764770
function testLonelyImport() {
765771
$oDoc = $this->parsedStructureForFile('lonely-import');
766772
$sExpected = "@import url(\"example.css\") only screen and (max-width: 600px);";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background-color: rgba(62,174,151,3.0418206565232E+21);
3+
z-index: 3.0418206565232E-2
4+
}

0 commit comments

Comments
 (0)