Skip to content

Commit 92f8281

Browse files
committed
fix: replaces \r\n (windows) and \r mac with \n
Dependabot uses `\r\n` as newlines in commit messages. Now parsing of Dependabot commit messages is possible too.
1 parent 6838c63 commit 92f8281

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

parse.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package cc
1919

2020
import (
21+
"bytes"
2122
"strings"
2223

2324
"github.com/bbuck/go-lexer"
@@ -63,7 +64,7 @@ func (c Commit) BreakingMessage() string {
6364

6465
// Parse parses the conventional commit. If it fails, an error is returned.
6566
func Parse(s string) (*Commit, error) {
66-
l := lexer.New(strings.TrimSpace(s), typeState)
67+
l := lexer.New(normalizeNewlines(strings.TrimSpace(s)), typeState)
6768
l.ErrorHandler = func(string) {}
6869

6970
l.Start()
@@ -118,3 +119,13 @@ func (f Footers) breakingMessage() string {
118119

119120
return ""
120121
}
122+
123+
func normalizeNewlines(s string) string {
124+
d := []byte(s)
125+
// replace CR LF \r\n (windows) with LF \n (unix)
126+
d = bytes.ReplaceAll(d, []byte{13, 10}, []byte{10})
127+
// replace CF \r (mac) with LF \n (unix)
128+
d = bytes.ReplaceAll(d, []byte{13}, []byte{10})
129+
130+
return string(d)
131+
}

0 commit comments

Comments
 (0)