diff options
author | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-03-15 12:15:04 +0300 |
---|---|---|
committer | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-03-15 12:15:04 +0300 |
commit | 3fa1494d4d1918374b848314a33a69806e5b9bdc (patch) | |
tree | cc166603acb8ab253b686dfc1f60d914cbd512f6 | |
parent | d53691700b7349ac56b0d9c8051c2a9529fbf25f (diff) | |
download | ydb-3fa1494d4d1918374b848314a33a69806e5b9bdc.tar.gz |
fix empty string interpretation as json
-rw-r--r-- | ydb/library/binary_json/read.h | 4 | ||||
-rw-r--r-- | ydb/library/binary_json/write.cpp | 15 |
2 files changed, 15 insertions, 4 deletions
diff --git a/ydb/library/binary_json/read.h b/ydb/library/binary_json/read.h index a9849d6a7a..63306edebe 100644 --- a/ydb/library/binary_json/read.h +++ b/ydb/library/binary_json/read.h @@ -7,6 +7,7 @@ #include <util/system/unaligned_mem.h> #include <util/generic/ptr.h> #include <util/generic/maybe.h> +#include <util/string/builder.h> namespace NKikimr::NBinaryJson { @@ -53,7 +54,8 @@ private: template <typename T> T ReadPOD(ui32 offset) const { static_assert(std::is_pod_v<T>, "Type must be POD"); - Y_ENSURE(offset <= Buffer.Size() && offset + sizeof(T) <= Buffer.Size(), "Not enough space in buffer to read value"); + Y_ENSURE(offset + sizeof(T) <= Buffer.Size(), + TStringBuilder() << "Not enough space in buffer to read value (" << offset << " + " << sizeof(T) << " > " << Buffer.Size() << ")"); return ReadUnaligned<T>(Buffer.Data() + offset); } diff --git a/ydb/library/binary_json/write.cpp b/ydb/library/binary_json/write.cpp index 0aee36f5d3..ced21d44bd 100644 --- a/ydb/library/binary_json/write.cpp +++ b/ydb/library/binary_json/write.cpp @@ -549,15 +549,24 @@ void DomToJsonIndex(const NUdf::TUnboxedValue& value, TBinaryJsonCallbacks& call } -TMaybe<TBinaryJson> SerializeToBinaryJson(const TStringBuf json) { +TMaybe<TBinaryJson> SerializeToBinaryJsonImpl(const TStringBuf json) { TMemoryInput input(json.data(), json.size()); TBinaryJsonCallbacks callbacks(/* throwException */ false); if (!ReadJson(&input, &callbacks)) { return Nothing(); } - TBinaryJsonSerializer serializer(std::move(callbacks).GetResult()); return std::move(serializer).Serialize(); + +} + +TMaybe<TBinaryJson> SerializeToBinaryJson(const TStringBuf json) { + if (json.size() == 0) { + return SerializeToBinaryJsonImpl("{}"); + } else { + return SerializeToBinaryJsonImpl(json); + } + } TBinaryJson SerializeToBinaryJson(const NUdf::TUnboxedValue& value) { @@ -567,4 +576,4 @@ TBinaryJson SerializeToBinaryJson(const NUdf::TUnboxedValue& value) { return std::move(serializer).Serialize(); } -}
\ No newline at end of file +} |