Skip to content

Commit 311cbe5

Browse files
authored
Enhance property access validation in Struct decoding (#6126)
1 parent cf7e2f0 commit 311cbe5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/types-codec/src/native/Struct.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function decodeStructFromObject (registry: Registry, [Types, keys]: Definition,
4343
} else if (typeofMap) {
4444
assign = jsonKey && value.get(jsonKey);
4545
} else {
46-
assign = jsonKey && value[jsonKey] as unknown;
46+
assign = jsonKey && Object.prototype.hasOwnProperty.call(value, jsonKey) ? value[jsonKey] as unknown : undefined;
4747

4848
if (isUndefined(assign)) {
4949
if (isUndefined(jsonObj)) {
@@ -52,11 +52,13 @@ function decodeStructFromObject (registry: Registry, [Types, keys]: Definition,
5252
jsonObj = {};
5353

5454
for (let e = 0, ecount = entries.length; e < ecount; e++) {
55-
jsonObj[stringCamelCase(entries[e][0])] = entries[e][1];
55+
if (Object.prototype.hasOwnProperty.call(value, entries[e][0])) {
56+
jsonObj[stringCamelCase(entries[e][0])] = entries[e][1];
57+
}
5658
}
5759
}
5860

59-
assign = jsonKey && jsonObj[jsonKey];
61+
assign = jsonKey && Object.prototype.hasOwnProperty.call(jsonObj, jsonKey) ? jsonObj[jsonKey] : undefined;
6062
}
6163
}
6264

0 commit comments

Comments
 (0)