-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle scientific notation when parsing sizes #179
Conversation
I’m not exactly sure what you mean. Size is exactly designed to handle numbers… But I agree that we should probably store additional metadata about how the size was formatted originally and provide ways for |
lib/Sabberworm/CSS/Value/Size.php
Outdated
@@ -28,9 +28,11 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal | |||
if ($oParserState->comes('-')) { | |||
$sSize .= $oParserState->consume('-'); | |||
} | |||
while (is_numeric($oParserState->peek()) || $oParserState->comes('.')) { | |||
while (is_numeric($oParserState->peek()) || $oParserState->comes('.') || $oParserState->comes('e+', true) || $oParserState->comes('e-', true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I’m not mistaken, the +
isn’t mandatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Fixed.
I was thinking of a |
Here is an overview of what got changed by this pull request: Issues
======
- Added 3
Complexity increasing per file
==============================
- lib/Sabberworm/CSS/Value/Size.php 2
See the complete overview on Codacy |
background-color: rgba(62,174,151,3.0418206565232E+21); | ||
z-index: 3.0418206565232E-2; | ||
font-size: 1em; | ||
top: 1.923478e2px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Unexpected token '1.923478e2px' at line 5, col 8.
@@ -0,0 +1,6 @@ | |||
body { | |||
background-color: rgba(62,174,151,3.0418206565232E+21); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Expected RBRACE at line 2, col 37.
@@ -0,0 +1,6 @@ | |||
body { | |||
background-color: rgba(62,174,151,3.0418206565232E+21); | |||
z-index: 3.0418206565232E-2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing numbers written in scientific notation raises
UnexpectedTokenException
. This PR fixes this.It might be a good idea to separate the number parsing and rendering from the
Size
class, however this will break backwards compatibility, so it might have to wait for a new major version release. Otherwise the numbers will have to extendSize
...