Skip to content

Commit 03e1c64

Browse files
authored
Resolve an issue when parsing the response to git.log that could leave part of the field separator in the preceding field. (#1024)
The default splitter ` ò ` surrounds the character with spaces that were being trimmed through a needless use of `String#trim` in the parser. Closes #985
1 parent 739b0d9 commit 03e1c64

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

.changeset/brave-avocados-dress.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'simple-git': patch
3+
---
4+
5+
Resolve error in log parsing when fields have empty values.

simple-git/src/lib/parsers/parse-list-log-summary.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ export function createListLogSummaryParser<T = any>(
3030

3131
return function (stdOut: string): LogResult<T> {
3232
const all: ReadonlyArray<T & ListLogLine> = toLinesWithContent(
33-
stdOut,
34-
true,
33+
stdOut.trim(),
34+
false,
3535
START_BOUNDARY
3636
).map(function (item) {
37-
const lineDetail = item.trim().split(COMMIT_BOUNDARY);
38-
const listLogLine: T & ListLogLine = lineBuilder(
39-
lineDetail[0].trim().split(splitter),
40-
fields
41-
);
37+
const lineDetail = item.split(COMMIT_BOUNDARY);
38+
const listLogLine: T & ListLogLine = lineBuilder(lineDetail[0].split(splitter), fields);
4239

4340
if (lineDetail.length > 1 && !!lineDetail[1].trim()) {
4441
listLogLine.diff = parseDiffResult(lineDetail[1]);

simple-git/test/unit/log.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,20 @@ ${START_BOUNDARY}ccc;;;;;2018-09-13 06:48:22 +0100;;;;;WIP on master: 2942035 bl
401401
);
402402
});
403403

404+
it('parses empty values', () => {
405+
const parser = createListLogSummaryParser(SPLITTER, ['a', 'b']);
406+
const actual = parser(`
407+
${START_BOUNDARY}f9ce27bb29e1a6971b7fdb7f19af6197be75061c${SPLITTER}ce55825${COMMIT_BOUNDARY}
408+
${START_BOUNDARY}ce55825e8dd96489be7bfedf456ac93c78fb3cfd${SPLITTER}${COMMIT_BOUNDARY}
409+
${START_BOUNDARY}${SPLITTER}${COMMIT_BOUNDARY}
410+
`);
411+
expect(actual.all).toEqual([
412+
{ a: 'f9ce27bb29e1a6971b7fdb7f19af6197be75061c', b: 'ce55825' },
413+
{ a: 'ce55825e8dd96489be7bfedf456ac93c78fb3cfd', b: '' },
414+
{ a: '', b: '' },
415+
]);
416+
});
417+
404418
it('parses regular log', () => {
405419
const parser = createListLogSummaryParser(splitOn.PIPES, ['hash', 'message']);
406420
actual = parser(`

0 commit comments

Comments
 (0)