Skip to content

Commit b8c2b9a

Browse files
authored
Merge pull request #1940 from murgatroid99/proto-loader_reject_array
proto-loader: Make serializers reject arrays
2 parents 6eb63e1 + 144c41b commit b8c2b9a

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

packages/proto-loader/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/proto-loader",
3-
"version": "0.6.5",
3+
"version": "0.6.6",
44
"author": "Google Inc.",
55
"contributors": [
66
{

packages/proto-loader/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ function createDeserializer(
212212

213213
function createSerializer(cls: Protobuf.Type): Serialize<object> {
214214
return function serialize(arg: object): Buffer {
215+
if (Array.isArray(arg)) {
216+
throw new Error(`Failed to serialize message: expected object with ${cls.name} structure, got array instead`);
217+
}
215218
const message = cls.fromObject(arg);
216219
return cls.encode(message).finish() as Buffer;
217220
};

0 commit comments

Comments
 (0)