rhomobile / rhodes

The Rhodes framework is a platform for building locally executing, device-optimized mobile applications for all major smartphone devices.
http://tau-platform.com/
MIT License
1.05k stars 237 forks source link

JSON parse long integer #967

Closed louisatome closed 6 years ago

louisatome commented 6 years ago

I've got a problem with the JSON parsing in rhodes. When I try to parse a JSON string with long integer, the result is incorrect :

Rho::JSON.parse('{"value" : 50000000000000000}')
# result => {"value"=>2147483647}

I use rhodes version 6.0.55 on android device. Any idea ?

louisatome commented 6 years ago

OK after some digging, it seems that the bug is linked to the code : https://github.com/rhomobile/rhodes/blob/e07a94be4606dfbcd5ff1aaab30c3b3f41955d9b/platform/shared/json.new/RJSONTokener.c#L86 It converts the long to an int32 but the value is over the max limit so it returns the INT32_MAX here : https://github.com/rhomobile/rhodes/blob/e07a94be4606dfbcd5ff1aaab30c3b3f41955d9b/platform/shared/json.new/json_object.c#L648

I've try to replace the json_object_get_int to json_object_get_int64 and it seems to work for my example. But i don't know if that's the proper way to fix it...

alex-epifanoff commented 6 years ago

Thanks @louisatome we'll try to fix it shortly