Skip to content

Commit 64c0c7e

Browse files
committed
test: add edge case for hex parsing
1 parent d821eb6 commit 64c0c7e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/testParsePush.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,17 @@ describe('parsePackFile', () => {
668668
expect(() => parsePacketLines(invalidLengthBuffer)).to.throw(/Invalid packet line length 000A/);
669669
});
670670

671-
it('should throw an error for non-hex length prefix', () => {
671+
it('should throw an error for non-hex length prefix (all non-hex)', () => {
672672
const invalidHexBuffer = Buffer.from('XXXXline');
673673
expect(() => parsePacketLines(invalidHexBuffer)).to.throw(/Invalid packet line length XXXX/);
674674
});
675675

676+
it('should throw an error for non-hex length prefix (non-hex at the end)', () => {
677+
// Cover the quirk of parseInt returning 0 instead of NaN
678+
const invalidHexBuffer = Buffer.from('000zline');
679+
expect(() => parsePacketLines(invalidHexBuffer)).to.throw(/Invalid packet line length 000z/);
680+
});
681+
676682
it('should handle buffer ending exactly after a valid line length without content', () => {
677683
// 0008 -> length 8, but buffer ends after header (no content)
678684
const incompleteBuffer = Buffer.from('0008');

0 commit comments

Comments
 (0)