fix(git): support numeric branch names

gitGraph does not support branch names that start with a number,
because the gitGraph.jison file parses these as NUM (number) instead.

To fix this, I've changed the NUM parser to only accept strings that
end with whitespace (e.g 1234 is a NUM, but 1234abc is not a NUM).
To do this, I had to move the "skip all whitespace" step to the
end of the parser, but this doesn't seem to have caused any issues,
so it's probably fine.
This commit is contained in:
Alois Klink
2022-09-01 17:20:36 +01:00
parent 5597cf45bf
commit 0dca4d3393
2 changed files with 18 additions and 3 deletions

View File

@@ -348,6 +348,21 @@ describe('when parsing a gitGraph', function () {
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
});
it('should allow branch names starting with numbers', function () {
const str = `gitGraph:
commit
%% branch names starting with numbers are not recommended, but are supported by git
branch 1.0.1
`;
parser.parse(str);
const commits = parser.yy.getCommits();
expect(Object.keys(commits).length).toBe(1);
expect(parser.yy.getCurrentBranch()).toBe('1.0.1');
expect(parser.yy.getDirection()).toBe('LR');
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
});
it('should handle new branch checkout', function () {
const str = `gitGraph:
commit