diff --git a/shell/platform/common/cpp/client_wrapper/standard_codec.cc b/shell/platform/common/cpp/client_wrapper/standard_codec.cc index 7c33fb4d969ec..137a3e849002c 100644 --- a/shell/platform/common/cpp/client_wrapper/standard_codec.cc +++ b/shell/platform/common/cpp/client_wrapper/standard_codec.cc @@ -176,8 +176,10 @@ void StandardCodecSerializer::WriteValue(const EncodableValue& value, const auto& string_value = value.StringValue(); size_t size = string_value.size(); WriteSize(size, stream); - stream->WriteBytes(reinterpret_cast(string_value.data()), - size); + if (size > 0) { + stream->WriteBytes( + reinterpret_cast(string_value.data()), size); + } break; } case EncodableValue::Type::kByteList: @@ -259,6 +261,9 @@ void StandardCodecSerializer::WriteVector( ByteBufferStreamWriter* stream) const { size_t count = vector.size(); WriteSize(count, stream); + if (count == 0) { + return; + } uint8_t type_size = static_cast(sizeof(T)); if (type_size > 1) { stream->WriteAlignment(type_size); diff --git a/shell/platform/common/cpp/client_wrapper/standard_message_codec_unittests.cc b/shell/platform/common/cpp/client_wrapper/standard_message_codec_unittests.cc index e56a44d62bebe..a0b4437b195f8 100644 --- a/shell/platform/common/cpp/client_wrapper/standard_message_codec_unittests.cc +++ b/shell/platform/common/cpp/client_wrapper/standard_message_codec_unittests.cc @@ -97,6 +97,11 @@ TEST(StandardMessageCodec, CanEncodeAndDecodeStringWithNonBMPCodePoint) { CheckEncodeDecode(EncodableValue(u8"h\U0001F602w"), bytes); } +TEST(StandardMessageCodec, CanEncodeAndDecodeEmptyString) { + std::vector bytes = {0x07, 0x00}; + CheckEncodeDecode(EncodableValue(u8""), bytes); +} + TEST(StandardMessageCodec, CanEncodeAndDecodeList) { std::vector bytes = { 0x0c, 0x05, 0x00, 0x07, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x06, @@ -117,6 +122,11 @@ TEST(StandardMessageCodec, CanEncodeAndDecodeList) { CheckEncodeDecode(value, bytes); } +TEST(StandardMessageCodec, CanEncodeAndDecodeEmptyList) { + std::vector bytes = {0x0c, 0x00}; + CheckEncodeDecode(EncodableValue(EncodableList{}), bytes); +} + TEST(StandardMessageCodec, CanEncodeAndDecodeMap) { std::vector bytes_prefix = {0x0d, 0x04}; EncodableValue value(EncodableMap{