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

Fixed locale floating point character #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

kyl3n
Copy link

@kyl3n kyl3n commented Jul 27, 2019

When running this code in locales that do not use a period for floating point integers, an error would occur. This is now resolved.

When running this code in locales that do not use a period for floating point integers, an error would occur. This is now resolved.
@kyl3n
Copy link
Author

kyl3n commented Aug 13, 2019

A bit of clarification. json.lua does not work on locales that use a decimal comma instead of a decimal point for floating point numbers, causing a Lua exception. There are about 80 countries who use decimal comma's.

https://en.wikipedia.org/wiki/Decimal_separator

@rxi
Copy link
Owner

rxi commented Aug 14, 2019

My understanding of the JSON specification is that only the . decimal separator should be supported:

https://tools.ietf.org/html/rfc7159#page-7

@kyl3n
Copy link
Author

kyl3n commented Aug 20, 2019

You are correct that it's in the JSON spec. However, this is a situation where the spec shouldn't come into play because of how Lua handles changing the locale.

  1. When you change the locale in Lua to a comma decimal region it changes all period decimals to comma decimals. Lua does not care if you haven't had time to process them yet.

  2. Decoding JSON format to Lua is not the same as Encoding to the proper JSON spec. What I'm saying here is that it is okay to decode from comma decimals in this instance. But when you encode it should still enforce the point decimal system.

The way you check if a JSON key with an integer is valid is a good way to check for valid numbers. But it still should adapt to Lua no matter what locale is being used.

previous version was replacing minus sign in negative numbers in error.
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.

2 participants