Skip to content

Commit

Permalink
Merge pull request #893 from stevenwdv/regex-patch
Browse files Browse the repository at this point in the history
Fix regex in parse-push.ts
  • Loading branch information
steveukx authored Feb 2, 2023
2 parents 0d44e0a + 9971b23 commit 1cf707d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilly-apples-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"simple-git": patch
---

Fix overly permissive regex in push parser
2 changes: 1 addition & 1 deletion simple-git/src/lib/parsers/parse-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const parsers: LineParser<PushDetail>[] = [
local,
};
}),
new LineParser(/^[*-=]\s+([^:]+):(\S+)\s+\[(.+)]$/, (result, [local, remote, type]) => {
new LineParser(/^[=*-]\s+([^:]+):(\S+)\s+\[(.+)]$/, (result, [local, remote, type]) => {
result.pushed.push(pushResultPushedItem(local, remote, type));
}),
new LineParser(
Expand Down
13 changes: 13 additions & 0 deletions simple-git/test/unit/push.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ describe('push', () => {
return aPushedBranch(local, remote, state, false);
}

it('will not match ill-formed push lines', () => {
givenTheResponse({
stdOut: [
'* refs/tags/tag-one:refs/tags/tag-one [up to date]',
'2 refs/tags/tag-one:refs/tags/tag-one [up to date]',
'= refs/tags/tag-one:refs/tags/tag-one [up to date]',
].join('\n'),
stdErr: '',
});

expect(actual.pushed).toHaveLength(2);
});

it('parses pushing tags as well as branches', () => {
givenTheResponse(pushNewBranchWithTags);
expect(actual).toEqual(
Expand Down

0 comments on commit 1cf707d

Please sign in to comment.