Skip to content

Commit d99e3b7

Browse files
committed
address review comments
1 parent 52f2a4a commit d99e3b7

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/mongo_logger.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,9 @@ export function stringifyWithMaxLen(
493493
currentLength += String(v.value).length;
494494
break;
495495
case 'Double':
496-
// Doesn't account for representing integers as <value>.0
497-
currentLength += String(v.value).length;
496+
// Account for representing integers as <value>.0
497+
currentLength +=
498+
(v.value | 0) === v.value ? String(v.value).length + 2 : String(v.value).length;
498499
break;
499500
case 'Long':
500501
currentLength += v.toString().length;
@@ -515,6 +516,7 @@ export function stringifyWithMaxLen(
515516
currentLength += (22 + value.position + value.position * 0.33 + 18) | 0;
516517
break;
517518
case 'Timestamp':
519+
// '{"$timestamp":{"t":<t>,"i":<i>}}'
518520
currentLength += 19 + String(v.t).length + 5 + String(v.i).length + 2;
519521
break;
520522
case 'Code':

test/unit/mongo_logger.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,16 +1623,14 @@ describe('class MongoLogger', function () {
16231623
});
16241624

16251625
describe('stringifyWithMaxLen', function () {
1626-
let returnVal: string;
1627-
16281626
describe('when stringifying a string field', function () {
16291627
it('does not prematurely redact the next key', function () {
16301628
const doc = {
16311629
a: 'aaa',
16321630
b: 'bbb'
16331631
};
16341632

1635-
returnVal = stringifyWithMaxLen(doc, 13);
1633+
const returnVal = stringifyWithMaxLen(doc, 13);
16361634
expect(returnVal).to.contain('"b...');
16371635
});
16381636
});
@@ -1643,7 +1641,7 @@ describe('stringifyWithMaxLen', function () {
16431641
a: 1000,
16441642
b: 'bbb'
16451643
};
1646-
returnVal = stringifyWithMaxLen(doc, 12);
1644+
const returnVal = stringifyWithMaxLen(doc, 12);
16471645

16481646
expect(returnVal).to.contain('"b...');
16491647
});
@@ -1655,7 +1653,7 @@ describe('stringifyWithMaxLen', function () {
16551653
a: 1000n,
16561654
b: 'bbb'
16571655
};
1658-
returnVal = stringifyWithMaxLen(doc, 12);
1656+
const returnVal = stringifyWithMaxLen(doc, 12);
16591657

16601658
expect(returnVal).to.contain('"b...');
16611659
});
@@ -1667,7 +1665,7 @@ describe('stringifyWithMaxLen', function () {
16671665
c: new Code('console.log();'),
16681666
b: 'bbb'
16691667
};
1670-
returnVal = stringifyWithMaxLen(doc, 34);
1668+
const returnVal = stringifyWithMaxLen(doc, 34);
16711669

16721670
expect(returnVal).to.contain('"b...');
16731671
});
@@ -1679,7 +1677,7 @@ describe('stringifyWithMaxLen', function () {
16791677
c: new Double(123.1),
16801678
b: 'bbb'
16811679
};
1682-
returnVal = stringifyWithMaxLen(doc, 13);
1680+
const returnVal = stringifyWithMaxLen(doc, 13);
16831681

16841682
expect(returnVal).to.contain('"b...');
16851683
});
@@ -1691,7 +1689,7 @@ describe('stringifyWithMaxLen', function () {
16911689
c: new Int32(123),
16921690
b: 'bbb'
16931691
};
1694-
returnVal = stringifyWithMaxLen(doc, 11);
1692+
const returnVal = stringifyWithMaxLen(doc, 11);
16951693

16961694
expect(returnVal).to.contain('"b...');
16971695
});
@@ -1703,7 +1701,7 @@ describe('stringifyWithMaxLen', function () {
17031701
c: new MaxKey(),
17041702
b: 'bbb'
17051703
};
1706-
returnVal = stringifyWithMaxLen(doc, 21);
1704+
const returnVal = stringifyWithMaxLen(doc, 21);
17071705

17081706
expect(returnVal).to.contain('"b...');
17091707
});
@@ -1715,7 +1713,7 @@ describe('stringifyWithMaxLen', function () {
17151713
c: new MinKey(),
17161714
b: 'bbb'
17171715
};
1718-
returnVal = stringifyWithMaxLen(doc, 21);
1716+
const returnVal = stringifyWithMaxLen(doc, 21);
17191717

17201718
expect(returnVal).to.contain('"b...');
17211719
});
@@ -1727,7 +1725,7 @@ describe('stringifyWithMaxLen', function () {
17271725
c: new ObjectId(),
17281726
b: 'bbb'
17291727
};
1730-
returnVal = stringifyWithMaxLen(doc, 43);
1728+
const returnVal = stringifyWithMaxLen(doc, 43);
17311729

17321730
expect(returnVal).to.contain('"b...');
17331731
});
@@ -1739,7 +1737,7 @@ describe('stringifyWithMaxLen', function () {
17391737
c: new BSONRegExp('testRegex', 'is'),
17401738
b: 'bbb'
17411739
};
1742-
returnVal = stringifyWithMaxLen(doc, 69);
1740+
const returnVal = stringifyWithMaxLen(doc, 69);
17431741

17441742
expect(returnVal).to.contain('"b...');
17451743
});

0 commit comments

Comments
 (0)