From 75787a62deab6864edd54ab1314d0fe26f1b7181 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 23 Sep 2025 12:29:32 +0200 Subject: [PATCH] [winpr,json] fix json-c case insensitive object get --- winpr/include/winpr/json.h | 4 ++-- winpr/libwinpr/utils/json/json.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/winpr/include/winpr/json.h b/winpr/include/winpr/json.h index 14a2433d8..a765161c5 100644 --- a/winpr/include/winpr/json.h +++ b/winpr/include/winpr/json.h @@ -119,14 +119,14 @@ extern "C" /** * @brief Return a pointer to an JSON object item * @param object the JSON object - * @param string the name of the object + * @param string the name of the object (case is ignored) * @return A pointer to the object identified by @ref string or \b NULL * @since version 3.6.0 */ WINPR_API WINPR_JSON* WINPR_JSON_GetObjectItem(const WINPR_JSON* object, const char* string); /** - * @brief Same as @ref WINPR_JSON_GetObjectItem but with case insensitive matching + * @brief Same as @ref WINPR_JSON_GetObjectItem but with case sensitive matching * * @param object the JSON instance to query * @param string the name of the object diff --git a/winpr/libwinpr/utils/json/json.c b/winpr/libwinpr/utils/json/json.c index e90b8d9c6..62f08f2df 100644 --- a/winpr/libwinpr/utils/json/json.c +++ b/winpr/libwinpr/utils/json/json.c @@ -184,7 +184,18 @@ size_t WINPR_JSON_GetArraySize(const WINPR_JSON* array) WINPR_JSON* WINPR_JSON_GetObjectItem(const WINPR_JSON* object, const char* string) { #if defined(WITH_JSONC) - return json_object_object_get((const json_object*)object, string); + struct json_object_iterator it = json_object_iter_begin((const json_object*)object); + struct json_object_iterator itEnd = json_object_iter_end((const json_object*)object); + while (!json_object_iter_equal(&it, &itEnd)) + { + const char* key = json_object_iter_peek_name(&it); + if (_stricmp(key, string) == 0) + { + return json_object_iter_peek_value(&it); + } + json_object_iter_next(&it); + } + return NULL; #elif defined(WITH_CJSON) return cJSON_GetObjectItem((const cJSON*)object, string); #else