-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_test.go
More file actions
33 lines (30 loc) · 861 Bytes
/
Copy pathhtml_test.go
File metadata and controls
33 lines (30 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package nerimity
import "testing"
func TestEscapeHTML(t *testing.T) {
tests := []struct {
in string
want string
}{
{`<script>`, `<script>`},
{`a & b`, `a & b`},
{`"quoted"`, `"quoted"`},
{`it's`, `it's`},
{`<img src="x" onerror='alert(1)'>`, `<img src="x" onerror='alert(1)'>`},
{`plain text`, `plain text`},
{``, ``},
}
for _, tt := range tests {
got := EscapeHTML(tt.in)
if got != tt.want {
t.Errorf("EscapeHTML(%q) = %q, want %q", tt.in, got, tt.want)
}
}
}
func TestEscapeHTMLAmpersandOrdering(t *testing.T) {
// & must be escaped first, otherwise escaping "<" to "<" and then "&"
// to "&" would double-escape it into "&lt;".
got := EscapeHTML("<")
if got != "<" {
t.Errorf("EscapeHTML(%q) = %q, want %q (double-escaping bug)", "<", got, "<")
}
}