Skip to content

Commit 8da44d1

Browse files
committed
escaping csv column content
1 parent 5304fa6 commit 8da44d1

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

modules/markup/csv/csv.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package markup
77
import (
88
"bytes"
99
"encoding/csv"
10+
"html"
1011
"io"
1112

1213
"code.gitea.io/gitea/modules/markup"
@@ -46,7 +47,7 @@ func (Parser) Render(rawBytes []byte, urlPrefix string, metas map[string]string,
4647
tmpBlock.WriteString("<tr>")
4748
for _, field := range fields {
4849
tmpBlock.WriteString("<td>")
49-
tmpBlock.WriteString(field)
50+
tmpBlock.WriteString(html.EscapeString(field))
5051
tmpBlock.WriteString("</td>")
5152
}
5253
tmpBlock.WriteString("<tr>")

modules/markup/csv/csv_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package markup
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestRenderCSV(t *testing.T) {
14+
var parser Parser
15+
var kases = map[string]string{
16+
"a": "<table class=\"table\"><tr><td>a</td><tr></table>",
17+
"1,2": "<table class=\"table\"><tr><td>1</td><td>2</td><tr></table>",
18+
"<br/>": "<table class=\"table\"><tr><td>&lt;br/&gt;</td><tr></table>",
19+
}
20+
21+
for k, v := range kases {
22+
res := parser.Render([]byte(k), "", nil, false)
23+
assert.EqualValues(t, v, string(res))
24+
}
25+
}

0 commit comments

Comments
 (0)