Skip to content

fix: prevent wrong formatting float values by locale #121

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
wants to merge 3 commits into from

Conversation

gpedro
Copy link

@gpedro gpedro commented Mar 3, 2020

resolves #84
that's the right-way fix. but to avoid install ext-intl, we can just replace comma by a dot.

@grimzy
Copy link
Owner

grimzy commented Mar 3, 2020

Looks good and tests are passing on my machine. Any idea why they're failing on Travis: https://travis-ci.org/grimzy/laravel-mysql-spatial/builds/657630242 ?

@gpedro
Copy link
Author

gpedro commented Mar 3, 2020

i have changed MAX_FRACTION_DIGITS from -1 to 12. reason to choose twelve:

Captura de Tela 2020-03-03 às 07 20 31

@gpedro
Copy link
Author

gpedro commented Mar 3, 2020

@grimzy
Copy link
Owner

grimzy commented Mar 6, 2020

I've delayed merging this PR because adding ext-intl would most likely break builds if I release a minor. I also want to avoid releasing a major and replacing a comma felt like a quick-fix (i18n-wise).

I'm going to test this out real quick: https://github.com/symfony/polyfill-intl-icu. It's already loaded when you build Laravel. This package adds ext-intl in composer's suggest and will use the PHP extension if it's already installed on the server.

@grimzy
Copy link
Owner

grimzy commented Mar 6, 2020

Thanks for fixing the tests.
I'm wondering if we're losing accuracy. Easy to test.
In any case, it doesn't seem that PHP compares floats past the 11th decimal either: https://github.com/grimzy/laravel-mysql-spatial/blob/2.2.0/tests/Integration/SpatialTest.php#L351 so we should be safe with 12 numbers after the decimal separator.

@grimzy
Copy link
Owner

grimzy commented Mar 6, 2020

With symfony/polyfill-intl-icu: https://github.com/grimzy/laravel-mysql-spatial/tree/fix/locale-polyfill

Edit: easier to see the changes in a PR: #126

@grimzy grimzy mentioned this pull request Mar 6, 2020
@gpedro gpedro closed this Mar 7, 2020
@monkeyphysics
Copy link

@grimzy This week I came across a MySQL error "Invalid GIS data provided" and ultimately tracked it down to my locale rendering floats with a comma when converted to strings. Then I just saw this issue, where the bug was presumably fixed. I am on version 4.0.0.

Is the fix still pending merge? Or is this a new issue?

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

Successfully merging this pull request may close these issues.

Invalid parameter value: 3037 Invalid GIS data provided to function st_geometryfromtext.
4 participants