From 76cd05e9fef8feab9178e2065dc2f01071aac3eb Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Mon, 18 Mar 2024 20:39:36 +0300 Subject: [PATCH] all: safer non-string json (fixes #3260) (#3265) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../org/ole/planet/myplanet/utilities/JsonUtils.kt | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4a81a6e981..7e3fdd480e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1423 - versionName "0.14.23" + versionCode 1424 + versionName "0.14.24" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/JsonUtils.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/JsonUtils.kt index c5576b93fa..acb67fdd7b 100644 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/JsonUtils.kt +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/JsonUtils.kt @@ -13,7 +13,13 @@ object JsonUtils { return try { if (jsonObject?.has(fieldName) == true) { val el: JsonElement = jsonObject.get(fieldName) - if (el is JsonNull) "" else el.asString + if (el is JsonNull) { + "" + } else if (el.isJsonPrimitive && el.asJsonPrimitive.isString) { + el.asString + } else { + "" + } } else { "" } @@ -166,4 +172,4 @@ object JsonUtils { 0L } } -} \ No newline at end of file +}