From 69cb25ef9c5a00fb824f76d52b46687bdabb5a59 Mon Sep 17 00:00:00 2001 From: Ashish Banerjee Date: Tue, 2 Jul 2024 15:45:21 +0000 Subject: [PATCH] Backport uncaught nlohmann json exception --- source/common/json/json_internal.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/common/json/json_internal.cc b/source/common/json/json_internal.cc index b01ac6e7863b..7065e880fb71 100644 --- a/source/common/json/json_internal.cc +++ b/source/common/json/json_internal.cc @@ -525,7 +525,9 @@ std::vector Field::asObjectArray() const { std::string Field::asJsonString() const { nlohmann::json j = asJsonDocument(); - return j.dump(); + // Call with defaults except in the case of UTF-8 errors which we replace + // invalid UTF-8 characters instead of throwing an exception. + return j.dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace); } bool Field::empty() const {