Skip to content

Commit 3c3c8eb

Browse files
committed
split on both LF and CRLF, use raw literals in regexes
1 parent 00763ed commit 3c3c8eb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

routers/repo/view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
214214
var terminator string
215215

216216
if strings.Index(fileContent, "\r\n") != -1 {
217-
lf, _ := regexp.MatchString("[^\r]\n", fileContent)
217+
lf, _ := regexp.MatchString(`[^\r]\n`, fileContent)
218218
if lf {
219219
terminator = "\n"
220220
} else {
@@ -223,7 +223,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
223223
} else {
224224
terminator = "\n"
225225
}
226-
lines := strings.Split(fileContent, terminator)
226+
lines := regexp.MustCompile(`\r?\n`).Split(fileContent, -1)
227227

228228
for index, line := range lines {
229229
line = gotemplate.HTMLEscapeString(line)

0 commit comments

Comments
 (0)