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

Values of type "double" should not use locale-specific encoding #1041

Closed
Grundik opened this issue Feb 21, 2019 · 1 comment
Closed

Values of type "double" should not use locale-specific encoding #1041

Grundik opened this issue Feb 21, 2019 · 1 comment

Comments

@Grundik
Copy link
Contributor

Grundik commented Feb 21, 2019

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Steps required to reproduce the problem

  1. Use locale with decimal separator other than dot, e.g. setlocale(LC_ALL, 'ru_RU.UTF-8')
  2. Try to serialize value of type double with fractional part, e.g. 1.234

Expected Result

  • Value should be encoded in using fixed format: no thousands separator, dot as fractional separator, e.g. "1.234"

Actual Result

  • Value encoded in locale-aware way, with locale-specific settings, e.g. "1,234", which will lead to parsing errors on produced serialized file.

This behaviour caused by converting double values to string type by using (string) operator:

    public function visitDouble($data, array $type, Context $context)
    {
        ...
            return $this->document->createTextNode((string) $data);
        ...

Easiest way to convert double to machine-readable string is using json_encode: json_encode((double)$data)

@Grundik
Copy link
Contributor Author

Grundik commented Feb 21, 2019

Fix: #1042

Grundik added a commit to Grundik/serializer that referenced this issue Feb 22, 2019
@goetas goetas closed this as completed in 84883f7 Feb 22, 2019
goetas added a commit that referenced this issue Feb 22, 2019
Non-locale aware encoding of doubles, closes #1041
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant