Skip to content

Commit

Permalink
fix crash caused by invalid number being set as property value
Browse files Browse the repository at this point in the history
  • Loading branch information
zihejia committed Jun 21, 2021
1 parent c16d1a7 commit 6caf099
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public static JSONObject reactToJSON(ReadableMap value) throws JSONException {
properties.put(key, value.getBoolean(key));
break;
case Number:
properties.put(key, value.getDouble(key));
double numberValue = value.getDouble(key);
if (!Double.isNaN(numberValue) && !Double.isInfinite(numberValue)) {
properties.put(key, numberValue);
} else {
properties.put(key, String.valueOf(numberValue));
}
break;
case String:
properties.put(key, value.getString(key));
Expand Down Expand Up @@ -77,7 +82,10 @@ public static JSONArray reactToJSON(ReadableArray value) throws JSONException {
properties.put(value.getBoolean(i));
break;
case Number:
properties.put(value.getDouble(i));
double numberValue = value.getDouble(i);
if (!Double.isNaN(numberValue) && !Double.isInfinite(numberValue)) {
properties.put(numberValue);
}
break;
case String:
properties.put(value.getString(i));
Expand Down Expand Up @@ -133,7 +141,12 @@ public static Map<String, Object> toMap(ReadableMap value) {
mapProperties.put(key, value.getBoolean(key));
break;
case Number:
mapProperties.put(key, value.getDouble(key));
double numberValue = value.getDouble(key);
if (!Double.isNaN(numberValue) && !Double.isInfinite(numberValue)) {
mapProperties.put(key, value.getDouble(key));
} else {
mapProperties.put(key, String.valueOf(numberValue));
}
break;
case String:
mapProperties.put(key, value.getString(key));
Expand Down

0 comments on commit 6caf099

Please sign in to comment.