Skip to content

Commit 34a7aa4

Browse files
committed
fix: Only decode top-level maps as arrays
1 parent 9dcf10b commit 34a7aa4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Decoder.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type StackMapState = {
7575
size: number;
7676
key: MapKeyType | null;
7777
readCount: number;
78-
map: Array<{key: MapKeyType, value: unknown}>;
78+
map: Array<{ key: MapKeyType; value: unknown }> | Record<string, unknown>;
7979
};
8080

8181
type StackArrayState = {
@@ -112,7 +112,12 @@ class StackPool {
112112
state.type = STATE_MAP_KEY;
113113
state.readCount = 0;
114114
state.size = size;
115-
state.map = [];
115+
116+
if (this.stackHeadPosition === 0) {
117+
state.map = [];
118+
} else {
119+
state.map = {};
120+
}
116121
}
117122

118123
private getUninitializedStateFromPool() {
@@ -572,7 +577,12 @@ export class Decoder<ContextType = undefined> {
572577
} else {
573578
// it must be `state.type === State.MAP_VALUE` here
574579

575-
state.map.push({ key: state.key!, value: object});
580+
if (Array.isArray(state.map)) {
581+
state.map.push({ key: state.key!, value: object });
582+
} else {
583+
state.map[state.key!] = object;
584+
}
585+
576586
state.readCount++;
577587

578588
if (state.readCount === state.size) {

0 commit comments

Comments
 (0)
close