-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] IntegerType: reject submitted non-integer numbers #30329
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
Conversation
xabbuh
commented
Feb 21, 2019
Q | A |
---|---|
Branch? | 3.4 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #10240 |
License | MIT |
Doc PR |
Status: Needs work |
...ymfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php
Outdated
Show resolved
Hide resolved
@@ -40,6 +42,12 @@ public function __construct($scale = 0, $grouping = false, $roundingMode = self: | ||
*/ | ||
public function reverseTransform($value) | ||
{ | ||
$decimalSeparator = $this->getNumberFormatter()->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); | ||
|
||
if (\is_string($value) && false !== strpos($value, $decimalSeparator)) { |
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.
The transformation is invoked in reverse order in DateIntervalType
when widget = integer, also in the model layer, so it could receive a real floating value here, isn't it?
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.
Can you give an example? I am not sure that I understand what you mean.
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.
symfony/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php
Lines 116 to 122 in 5a3e894
if ('integer' === $options['widget']) { | |
$childForm->addModelTransformer( | |
new ReversedTransformer( | |
new IntegerToLocalizedStringTransformer() | |
) | |
); | |
} |
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.
Unlike IntegerType
this transformation is invoked for model layer in reversed order, so I guess we should deal with real float values here.
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.
Basically, this is what I suggest:
if (false !== strpos((string) $value, $decimalSeparator)) {
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.
Although, technically that should never happen because DateIntervalToArrayTransformer
, so ignore my suggestion.
Thank you @xabbuh. |
…xabbuh) This PR was merged into the 3.4 branch. Discussion ---------- [Form] IntegerType: reject submitted non-integer numbers | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10240 | License | MIT | Doc PR | Commits ------- 6a43e74 IntegerType: reject submitted non-integer numbers