-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
ExpressionLanguage unable to parse decimal numbers without leading zeros #44014
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
Comments
Status: reviewed I looked at this. IMO the problem is on the lexer side. The regex used to detect numbers is not in sync with how PHP can currently cast strings to floats. I recomputed the following regex from https://github.com/php/php-src/blob/ddaf64b56c88f0ae223b1aca25293dd7fec77fc0/Zend/zend_language_scanner.l#L1359: It seems to fix everything and also other cases such as having underscores in the number. @nicolas-grekas @derrabus Do we consider this a bugfix on 4.4 and craft the regex pattern depending of the PHP version (the underscores were not allowed before 7.4) or do we consider supporting all those new cases as a feature on 6.1? |
I consider this a feature, there's no bug here, the syntax is clear: the leading zero is required :) |
The ExpressionLanguage lexer is responsible for supporting the ExpressionLanguage syntax, not the PHP one. So there is indeed no bug here. This is more a feature request. |
Thank you for looking into this and for the discussion.
I'm not sure that the syntax is clear. The documentation indeed lists the various supported literals, including "numbers - e.g. 103" but without any caveats that says that these literals are not interpreted/treated the same as PHP. (Perhaps this is mentioned in the code, but that's not the same and I had not gone that deep yet.) The main argument for supporting no leading zeros is that it seems odd not to.
Additionally I think developers would generally expect similar (if not exact) behavior, and as the main reason we started using ExpressionLanguage was to validate/parse user input, not to support an otherwise valid input requires a need to pre-validate/parse the entire input just to insert the missing leading zeros, the very task we wanted to avoid. In the meantime, should we update the documentation to reflect this? I would be happy to submit a PR over there. |
Well, the ExpressionLanguage lexer was originally created based on the Twig lexer (the syntax to access properties and methods is inspired by Twig, with the magic of |
I opened #44073 since I had already made the "work". Let's see where it goes there 😄 |
…scores and decimals with no leading zero (fancyweb) This PR was merged into the 6.1 branch. Discussion ---------- [ExpressionLanguage] Support lexing numbers with underscores and decimals with no leading zero | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #44014 | License | MIT | Doc PR | - I understand that the supported Expression Language syntax is, and can be different than the PHP syntax, however, like `@epixian`, I would have expected `.123` to work since it's a common notation. Supporting the numeric literal separator `_` looks good to me for the readability (the expression language is still code IMO). As most of us are PHP devs, we know this syntax. Supporting those new syntaxes doesn't really bring more complexity in the code and it allows us to realign with the PHP behavior (thus having a guide) which is not something mandatory but something a random user would expect I think, that's why it improves the DX IMHO. We could make the change in Twig too for the same reasons. We could also support the hexadecimal, binary and octal syntaxes but let's wait for someone that actually needs it 😃 Commits ------- bb56b2e [ExpressionLanguage] Support lexing numbers with underscores and decimals with no leading zero
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
5.3.7
Description
ExpressionLanguage is unable to parse decimal numbers without leading zeros.
Invalid expressions:
"-.1"
"0-.1"
"0+.1"
".1"
Valid expressions:
"-0.1"
"0-0.1"
"0+0.1"
How to reproduce
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: