[Common] Fixed invalid parsing of decimal values 59/252459/1
authorPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Thu, 28 Jan 2021 09:57:03 +0000 (10:57 +0100)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Thu, 28 Jan 2021 11:14:39 +0000 (12:14 +0100)
[Bug] Decimal values fails to parse properly when locale of device
was e.g. Deutsch

[Verification]
//Below code works well for locales: English, Deutsch, Francais
// sound values are changing and show aproximately same values
// (depending on platform adjustments)

tizen.sound.setVolume("MEDIA", 0.1);
console.log(tizen.sound.getVolume("MEDIA"))
>> 0.13

Change-Id: Icde211bcfcc66cf0d66852816d2a00907adf4571

src/common/extension.cc
src/common/picojson.h

index 9fc1547..71d3db0 100644 (file)
@@ -332,7 +332,7 @@ void ParsedInstance::HandleMessage(const char* msg, bool is_sync) {
     std::string err;
     picojson::parse(value, msg, msg + strlen(msg), &err);
     if (!err.empty()) {
-      LoggerE("Ignoring message, error: %s", err.c_str());
+      LoggerE("Ignoring message:\"%s\", error: %s", msg, err.c_str());
       return;
     }
 
index c6b9ade..54a40a7 100644 (file)
@@ -916,7 +916,9 @@ inline bool _parse(Context &ctx, input<Iter> &in) {
           }
         }
 #endif
-        f = strtod(num_str.c_str(), &endp);
+        locale_t loc = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
+        f = strtod_l(num_str.c_str(), &endp, loc);
+        freelocale(loc);
         if (endp == num_str.c_str() + num_str.size()) {
           ctx.set_number(f);
           return true;