Skip to content

Commit 3743014

Browse files
committed
fix(header): Read description delimiter exactly as ": "
This fixes an issue where a commit header like this: `type(scope): 💡 look a light bulb!` will case an error. `lexer.Take()` is greedy and will read `: :` into the `Current()` token and thus will fail the comparison to the expected delimiter (`: `).
1 parent 55464a6 commit 3743014

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lexer_state.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,13 @@ func descriptionDelimiterState(l *lexer) stateFunc {
111111
l.Emit(breakingChangeToken)
112112
}
113113

114-
l.Take(": ")
114+
l.Next()
115115

116-
if l.Current() != ": " {
116+
if l.Current() != ":" || l.Peek() != ' ' {
117117
l.Error(errDescMissingDelimiter)
118118
return nil
119119
}
120+
l.Next()
120121

121122
l.Emit(descDelimiterToken)
122123

parser_header_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ func TestParseHeaderValid(t *testing.T) {
1717
"feat: description with body 1, \n\n2, 3 and 4?",
1818
"feat1234(@scope/scope1,scope2): description, \n\n body 1 2, 3 and 4?",
1919
"1245#feat1234(@scope/scope1,scope2): description, \n\n body 1 2, 3 and 4?",
20+
"feat: description with colon at the end: mid:dle and :start of words",
21+
"feat: description with gitmoji at the end :hammer:",
22+
"feat: description with gitmoji in :hammer: the middle",
23+
"feat: :hammer: description with gitmoji at the start",
24+
"feat(scope): description with colon at the end: mid:dle and :start of words",
25+
"feat(scope): description with gitmoji at the end :hammer:",
26+
"feat(scope): description with gitmoji in :hammer: the middle",
27+
"feat(scope): :hammer: description with gitmoji at the start",
28+
"feat!: description with colon at the end: mid:dle and :start of words",
29+
"feat!: description with gitmoji at the end :hammer:",
30+
"feat!: description with gitmoji in :hammer: the middle",
31+
"feat!: :hammer: description with gitmoji at the start",
32+
"feat(scope)!: description with colon at the end: mid:dle and :start of words",
33+
"feat(scope)!: description with gitmoji at the end :hammer:",
34+
"feat(scope)!: description with gitmoji in :hammer: the middle",
35+
"feat(scope)!: :hammer: description with gitmoji at the start",
36+
`feat: : : A description`,
37+
`feat: :: A description ::`,
2038
}
2139

2240
p := New()
@@ -52,6 +70,8 @@ func TestParseHeaderInvalid(t *testing.T) {
5270
`feat((`,
5371
`feat():`,
5472
`feat):`,
73+
`feat:: A description`,
74+
`feat:::: A description`,
5575
}
5676

5777
p := New()

0 commit comments

Comments
 (0)