Skip to content

Commit 81897e7

Browse files
authored
Merge pull request #179 from raxbg/fix/size_parsing
2 parents eeece76 + c97b614 commit 81897e7

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/Value/Size.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,16 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal
7777
if ($oParserState->comes('-')) {
7878
$sSize .= $oParserState->consume('-');
7979
}
80-
while (is_numeric($oParserState->peek()) || $oParserState->comes('.')) {
80+
while (is_numeric($oParserState->peek()) || $oParserState->comes('.') || $oParserState->comes('e', true)) {
8181
if ($oParserState->comes('.')) {
8282
$sSize .= $oParserState->consume('.');
83+
} elseif ($oParserState->comes('e', true)) {
84+
$sLookahead = $oParserState->peek(1, 1);
85+
if (is_numeric($sLookahead) || $sLookahead === '+' || $sLookahead === '-') {
86+
$sSize .= $oParserState->consume(2);
87+
} else {
88+
break; // Reached the unit part of the number like "em" or "ex"
89+
}
8390
} else {
8491
$sSize .= $oParserState->consume(1);
8592
}

tests/ParserTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,21 @@ public function largeSizeValuesInFile()
11711171
self::assertSame($sExpected, $oDoc->render());
11721172
}
11731173

1174+
/**
1175+
* @test
1176+
*/
1177+
public function scientificNotationSizeValuesInFile()
1178+
{
1179+
$oDoc = $this->parsedStructureForFile(
1180+
'scientific-notation-numbers',
1181+
Settings::create()->withMultibyteSupport(false)
1182+
);
1183+
$sExpected = ''
1184+
. 'body {background-color: rgba(62,174,151,3041820656523200167936);'
1185+
. 'z-index: .030418206565232;font-size: 1em;top: 192.3478px;}';
1186+
self::assertSame($sExpected, $oDoc->render());
1187+
}
1188+
11741189
/**
11751190
* @test
11761191
*/
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)