Skip to content

Commit 35fc088

Browse files
committed
address review
1 parent d99e3b7 commit 35fc088

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/mongo_logger.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,16 @@ export function stringifyWithMaxLen(
466466
}
467467

468468
// +4 accounts for 2 quotation marks, colon and comma after value
469+
// Note that this potentially undercounts since it does not account for escape sequences which
470+
// will have an additional backslash added to them once passed through JSON.stringify.
469471
currentLength += key.length + 4;
470472

471473
if (value == null) return value;
472474

473475
switch (typeof value) {
474476
case 'string':
475477
// +2 accounts for quotes
478+
// Note that this potentially undercounts similarly to the key length calculation
476479
currentLength += value.length + 2;
477480
break;
478481
case 'number':
@@ -483,9 +486,9 @@ export function stringifyWithMaxLen(
483486
currentLength += value ? 4 : 5;
484487
break;
485488
case 'object':
486-
if ('buffer' in value && isUint8Array(value.buffer)) {
489+
if (isUint8Array(value)) {
487490
// Handle binData
488-
currentLength += (value.buffer.byteLength + value.buffer.byteLength * 0.5) | 0;
491+
currentLength += (value.byteLength + value.byteLength * 0.5) | 0;
489492
} else if ('_bsontype' in value) {
490493
const v = value as BSONObject;
491494
switch (v._bsontype) {

0 commit comments

Comments
 (0)