summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2017-06-10 17:20:25 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2017-06-10 23:20:25 +0800
commitf2fcd9dcd834b611d2f321829e814a741054c4ea (patch)
treebf1cb86de7ea1c4a1b938a2b98ef7b36cc46b959 /routers
parent446a41d595c2a3477aa55b8e78e625bcdff42eb6 (diff)
downloadgitea-f2fcd9dcd834b611d2f321829e814a741054c4ea.tar.gz
gitea-f2fcd9dcd834b611d2f321829e814a741054c4ea.zip
Support CRLF when splitting code lines for display (#1862)
* Support CRLF when splitting code lines for display * refactor, fix mixed match * fmt * split on both LF and CRLF, use raw literals in regexes * simplify
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/view.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go
index a3c42a0fdd..84e5ba85ce 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -212,7 +212,11 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
var output bytes.Buffer
lines := strings.Split(fileContent, "\n")
for index, line := range lines {
- output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, gotemplate.HTMLEscapeString(line)) + "\n")
+ line = gotemplate.HTMLEscapeString(line)
+ if index != len(lines)-1 {
+ line += "\n"
+ }
+ output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, line))
}
ctx.Data["FileContent"] = gotemplate.HTML(output.String())