`,
// html is disallowed in a pipeline that is in an unquoted attribute context,
// even if it is the last command in the pipeline.
`predefined escaper "html" disallowed in template`,
},
{
`Hello, {{. | urlquery | html}}!`,
// html is allowed since it is the last command in the pipeline, but urlquery is not.
`predefined escaper "urlquery" disallowed in template`,
},
}
for _, test := range tests {
buf := new(bytes.Buffer)
tmpl, err := New("z").Parse(test.input)
if err != nil {
t.Errorf("input=%q: unexpected parse error %s\n", test.input, err)
continue
}
err = tmpl.Execute(buf, nil)
var got string
if err != nil {
got = err.Error()
}
if test.err == "" {
if got != "" {
t.Errorf("input=%q: unexpected error %q", test.input, got)
}
continue
}
if !strings.Contains(got, test.err) {
t.Errorf("input=%q: error\n\t%q\ndoes not contain expected string\n\t%q", test.input, got, test.err)
continue
}
// Check that we get the same error if we call Execute again.
if err := tmpl.Execute(buf, nil); err == nil || err.Error() != got {
t.Errorf("input=%q: unexpected error on second call %q", test.input, err)
}
}
}
func TestEscapeText(t *testing.T) {
tests := []struct {
input string
output context
}{
{
``,
context{},
},
{
`Hello, World!`,
context{},
},
{
// An orphaned "<" is OK.
`I <3 Ponies!`,
context{},
},
{
`
`,
context{state: stateText},
},
{
``,
context{state: stateText},
},
{
``,
context{state: stateText},
},
{
``,
context{state: stateText},
},
{
``,
context{state: stateText},
},
{
`/foo/ /=`,
context{state: stateJS, element: elementScript},
},
{
``,
context{state: stateCSSLineCmt, delim: delimDoubleQuote, attr: attrStyle},
},
{
"`,
context{state: stateJS, jsCtx: jsCtxRegexp, element: elementScript},
},
{
``,
context{state: stateText},
},
{
`
您还没有登录,登录后您可以:
-
收藏Android系统代码
-
收藏喜欢的文章
-
多个平台共享账号
去登录
首次使用?从这里 注册