Thanks to visit codestin.com
Credit goes to github.com

Skip to content

NumberToLocalizedStringTransformer incorrect reverseTransform #28500

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

Closed
koutja opened this issue Sep 18, 2018 · 8 comments
Closed

NumberToLocalizedStringTransformer incorrect reverseTransform #28500

koutja opened this issue Sep 18, 2018 · 8 comments

Comments

@koutja
Copy link

koutja commented Sep 18, 2018

Symfony version(s) affected: 3.4.15
PHP 7.2

Description

Unable to reverse value for property path "foo": The number contains unrecognized characters: "."
when valeu equal '239.' or other string contains number with dot in end.
It was happend in class Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer when call method reverseTransform

How to reproduce

  1. Create form like this
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('foo', NumberType::class, ['required' => false]);
    }
  1. submit values and check valid
$form->submit([
    'foo' => '239.'
]);
if (!$form->isValid()){
    echo 'form is not valid';
}

OR

$transformer = NumberToLocalizedStringTransformer();
$transformer->reverseTransform('239.');

Possible Solution

Additional context

@xabbuh
Copy link
Member

xabbuh commented Sep 18, 2018

I was not able to reproduce your issue. What value is returned by \Locale::getDefault() when this fails for you?

@koutja
Copy link
Author

koutja commented Sep 18, 2018

"en" is returned by \Locale::getDefault()

@koutja
Copy link
Author

koutja commented Sep 18, 2018

image

@koutja
Copy link
Author

koutja commented Sep 18, 2018

I forget say, that I use php version 7.2.9. But same with php 7.0
composer.json
"config": { "platform": { "php": "7.0.8" } }, ... "require": { "php": "7.0.*||7.2.*", .... }

@xabbuh
Copy link
Member

xabbuh commented Sep 18, 2018

Can you please dump the values of the $result, $length, $remainder, $position, and $length variables when the exception is thrown?

@koutja
Copy link
Author

koutja commented Sep 18, 2018

dump

NumberToLocalizedStringTransformer.php on line 210:
array:7 [
  "$result" => 239.0
  "$remainder" => "."
  "$position" => 3
  "$length" => 4
  "$formatter" => NumberFormatter {#1415
    #errorCode: 0
    #errorMessage: "U_ZERO_ERROR"
    -style: 1
    -attributes: array:3 [
      8 => 0
      1 => 0
      11 => 4
    ]
    -initializedAttributes: array:1 [
      1 => true
    ]
  }
  "$groupSep" => ","
  "$decSep" => "."
  "$encoding" => "ASCII"
]
NumberToLocalizedStringTransformer.php on line 212:
NumberToLocalizedStringTransformer {#1377
  #grouping: false
  #roundingMode: 6
  -scale: null
}

@xabbuh
Copy link
Member

xabbuh commented Sep 18, 2018

I can confirm the issue when the NumberFormatter shipped with the Intl component is being used.

Status: Reviewed

@xabbuh
Copy link
Member

xabbuh commented Sep 21, 2018

see #28540

nicolas-grekas added a commit that referenced this issue Sep 22, 2018
…bbuh)

This PR was merged into the 2.8 branch.

Discussion
----------

[Intl] parse numbers terminated with decimal separator

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28500
| License       | MIT
| Doc PR        |

Commits
-------

4225f36 parse numbers terminated with decimal separator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants