-
Notifications
You must be signed in to change notification settings - Fork 56
/
escape_test.go
43 lines (35 loc) · 1.03 KB
/
escape_test.go
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
34
35
36
37
38
39
40
41
42
43
package plush_test
import (
"html/template"
"testing"
"github.com/gobuffalo/plush/v5"
"github.com/stretchr/testify/require"
)
func Test_Render_EscapedString(t *testing.T) {
r := require.New(t)
input := `<p><%= "<script>alert('pwned')</script>" %></p>`
s, err := plush.Render(input, plush.NewContext())
r.NoError(err)
r.Equal("<p><script>alert('pwned')</script></p>", s)
}
func Test_Render_HTML_Escape(t *testing.T) {
r := require.New(t)
input := `<%= escapedHTML() %>|<%= unescapedHTML() %>|<%= raw("<b>unsafe</b>") %>`
s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{
"escapedHTML": func() string {
return "<b>unsafe</b>"
},
"unescapedHTML": func() template.HTML {
return "<b>unsafe</b>"
},
}))
r.NoError(err)
r.Equal("<b>unsafe</b>|<b>unsafe</b>|<b>unsafe</b>", s)
}
func Test_Escaping_EscapeExpression(t *testing.T) {
r := require.New(t)
input := `C:\\<%= "temp" %>`
s, err := plush.Render(input, plush.NewContext())
r.NoError(err)
r.Equal(`C:\temp`, s)
}