Skip to content

Commit 529c463

Browse files
committed
fix: return null for zero bytes payloads
1 parent b9402e7 commit 529c463

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/src/core/content_serdes.dart

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ class ContentSerdes {
230230

231231
final bytes = await content.byteBuffer;
232232

233+
// TODO: Should null be returned in this case?
234+
if (bytes.lengthInBytes == 0) {
235+
return null;
236+
}
237+
233238
final codec = _getCodecFromMediaType(mimeType);
234239
if (codec != null) {
235240
final value = codec.bytesToValue(bytes, dataSchema, parameters);

test/core/content_serdes_test.dart

+6
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,11 @@ void main() {
4545
() => contentSerdes.valueToContent(42, failingSchema, 'application/json'),
4646
throwsA(const TypeMatcher<ContentSerdesException>()),
4747
);
48+
49+
final testContent3 = _getTestContent('');
50+
expect(
51+
await contentSerdes.contentToValue(testContent3, null),
52+
null,
53+
);
4854
});
4955
}

0 commit comments

Comments
 (0)