Skip to content
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

[Form] IntegerType: reject submitted non-integer numbers #30329

Merged
merged 1 commit into from Feb 23, 2019

Conversation

xabbuh
Copy link
Member

@xabbuh 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

@xabbuh
Copy link
Member Author

xabbuh commented Feb 21, 2019

Status: Needs work

@@ -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)) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ('integer' === $options['widget']) {
$childForm->addModelTransformer(
new ReversedTransformer(
new IntegerToLocalizedStringTransformer()
)
);
}

Copy link
Member

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.

Copy link
Member

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)) {

Copy link
Member

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.

@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit 6a43e74 into symfony:3.4 Feb 23, 2019
nicolas-grekas added a commit that referenced this pull request Feb 23, 2019
…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
@xabbuh xabbuh deleted the issue-10240 branch February 23, 2019 15:13
This was referenced Mar 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants