Skip to content

Commit a118817

Browse files
committed
fix: handle empty input by returning empty array from parseGitZOutput
1 parent e8291b0 commit a118817

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/parseGitZOutput.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
*/
66
export const parseGitZOutput = (input) =>
77
input
8-
.replace(/\u0000$/, '') // eslint-disable-line no-control-regex
9-
.split('\u0000')
8+
? input
9+
.replace(/\u0000$/, '') // eslint-disable-line no-control-regex
10+
.split('\u0000')
11+
: []

test/parseGitZOutput.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ describe('parseGitZOutput', () => {
1010
const input = 'a\u0000'
1111
expect(parseGitZOutput(input)).toEqual(['a'])
1212
})
13+
14+
it('should handle empty input', () => {
15+
const input = ''
16+
expect(parseGitZOutput(input)).toEqual([])
17+
})
1318
})

0 commit comments

Comments
 (0)