` +
// Illegal starting in stateTag but not in stateText.
`{{define "y"}} foo
reverseList = [{{template "t"}}]` +
// Missing " after recursive call.
`{{define "t"}}{{if .Tail}}{{template "t" .Tail}}{{end}}{{.Head}}",{{end}}`,
`: cannot compute output context for template t$htmltemplate_stateJS_elementScript`,
},
{
``,
`html/template:z: "=" in unquoted attr: "onclick="`,
},
{
``,
`html/template:z: "=" in unquoted attr: "onclick="`,
},
{
``,
`html/template:z: "=" in unquoted attr: "1+1=2"`,
},
{
"",
"html/template:z: \"`\" in unquoted attr: \"`foo\"",
},
{
``,
`html/template:z: "'" in unquoted attr: "font:'Arial'"`,
},
{
``,
`: expected space, attr name, or end of tag, but got "=foo>"`,
},
}
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.Index(got, test.err) == -1 {
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},
},
{
"foo`,
context{state: stateJS, jsCtx: jsCtxDivOp, element: elementScript},
},
{
``,
context{state: stateText},
},
{
`
您还没有登录,登录后您可以:
-
收藏Android系统代码
-
收藏喜欢的文章
-
多个平台共享账号
去登录
首次使用?从这里 注册