Skip to content

Commit 7faa0c4

Browse files
authored
Update KBinJSON.ts
Fix when pug introduced an empty element
1 parent 489bf51 commit 7faa0c4

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/utils/KBinJSON.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,16 @@ function nodeToBinary(
505505
binaryType = 'u8';
506506
}
507507

508+
// Normalize missing or malformed content so kencode doesn't crash.
509+
if (value === null || value === undefined) {
510+
// If node is flagged as array (via __count), default to an empty array.
511+
// Otherwise default to a single zero value for numeric types.
512+
value = isArray ? [] : [0];
513+
} else if (!Array.isArray(value)) {
514+
// Ensure numeric/binary values are arrays for the writer APIs.
515+
value = [value as number | bigint];
516+
}
517+
508518
if (isArray) {
509519
dataBuf.writeArray(binaryType as BinaryLengthType, value as (number | bigint)[]);
510520
} else {

0 commit comments

Comments
 (0)