Skip to content

Commit 3778a1c

Browse files
committed
Merge branch 'fix/size_parsing' into catchup/size_parsing
2 parents 1a874ce + 0359543 commit 3778a1c

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

lib/Sabberworm/CSS/Value/Size.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal
3535
while (is_numeric($oParserState->peek()) || $oParserState->comes('.')) {
3636
if ($oParserState->comes('.')) {
3737
$sSize .= $oParserState->consume('.');
38+
} elseif ($oParserState->comes('e', true)) {
39+
$sLookahead = $oParserState->peek(1, 1);
40+
if (is_numeric($sLookahead) || $sLookahead === '+' || $sLookahead === '-') {
41+
$sSize .= $oParserState->consume(2);
42+
} else {
43+
break; // Reached the unit part of the number like "em" or "ex"
44+
}
3845
} else {
3946
$sSize .= $oParserState->consume(1);
4047
}

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,12 @@ public function testLargeSizeValuesInFile()
847847
$this->assertSame($sExpected, $oDoc->render());
848848
}
849849

850+
public function testScientificNotationSizeValuesInFile() {
851+
$oDoc = $this->parsedStructureForFile('scientific-notation-numbers', Settings::create()->withMultibyteSupport(false));
852+
$sExpected = 'body {background-color: rgba(62,174,151,3041820656523200167936);z-index: .030418206565232;font-size: 1em;top: 192.3478px;}';
853+
self::assertSame($sExpected, $oDoc->render());
854+
}
855+
850856
public function testLonelyImport()
851857
{
852858
$oDoc = $this->parsedStructureForFile('lonely-import');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
body {
2+
background-color: rgba(62,174,151,3.0418206565232E+21);
3+
z-index: 3.0418206565232E-2;
4+
font-size: 1em;
5+
top: 1.923478e2px;
6+
}

0 commit comments

Comments
 (0)