golang/go

html/template: unidentified node type in allIdents (2)

dvyukov opened this issue · 2 comments

package main

import (
    "errors"
    "html/template"
    "io/ioutil"
)

func main() {
    data := "</a>query}}\"\x9b\xaa\x9015186" +
        "77827595\"}\"\x9b\xaa\x90518677" +
        "82759541638>{{-6| ht" +
        "ml}}</a>Z\x10\x96ear}\"\x9b\xaa\x901" +
        "51867782759541638>{{" +
        "-643773943| html}}</" +
        "a>Z\x10\x96earh?q={cx\x00\x02={{" +
        ".stateError | urlque" +
        "ry}}\"\x9b\xaa\x901.1867782759" +
        "541638>{{. | html.y}" +
        "}</a>"

    t, err := template.New("foo").Funcs(funcs).Parse(string(data))
    if err != nil {
        if t != nil {
            panic("non nil template on error")
        }
        return
    }
    d := &Data{
        A: 42,
        B: "foo",
        C: []int{1, 2, 3},
        D: map[int]string{1: "foo", 2: "bar"},
        E: Data1{42, "foo"},
    }
    t.Execute(ioutil.Discard, d)
    return
}

type Data struct {
    A int
    B string
    C []int
    D map[int]string
    E Data1
}

type Data1 struct {
    A int
    B string
}

func (Data1) Q() string {
    return "foo"
}

func (Data1) W() (string, error) {
    return "foo", nil
}

func (Data1) E() (string, error) {
    return "foo", errors.New("Data.E error")
}

func (Data1) R(v int) (string, error) {
    return "foo", nil
}

func (Data1) T(s string) (string, error) {
    return s, nil
}

var funcs = map[string]interface{}{
    "Q": func1,
    "W": func2,
    "E": func3,
    "R": func4,
    "T": func5,
    "Y": func6,
    "U": func7,
    "I": func8,
}

func func1(s string) string {
    return s
}

func func2(s string) (string, error) {
    return s, nil
}

func func3(s string) (string, error) {
    return s, errors.New("func3 error")
}

func func4(v int) int {
    return v
}

func func5(v int) (int, error) {
    return v, nil
}

func func6() int {
    return 42
}

func func7() (int, error) {
    return 42, nil
}

func func8() (int, error) {
    return 42, errors.New("func8 error")
}
panic: unidentified node type in allIdents

goroutine 1 [running]:
html/template.allIdents(0x7f11258d8588, 0xc208010500, 0x0, 0x0, 0x0)
    src/html/template/escape.go:216 +0x1f1
html/template.ensurePipelineContains(0xc2080122d0, 0xc208015020, 0x1, 0x3)
    src/html/template/escape.go:242 +0x1ca
html/template.(*escaper).commit(0xc208043cc8)
    src/html/template/escape.go:749 +0x36c
html/template.escapeTemplate(0xc208014720, 0x7f11258d85d0, 0xc208014810, 0x5c9fd0, 0x3, 0x0, 0x0)
    src/html/template/escape.go:39 +0x46c
html/template.(*Template).escape(0xc208014720, 0x0, 0x0)
    src/html/template/template.go:85 +0x388
html/template.(*Template).Execute(0xc208014720, 0x7f11258d8388, 0xc20800a510, 0x52fc40, 0xc208012320, 0x0, 0x0)
    src/html/template/template.go:101 +0x37
main.main()
    /tmp/ht.go:36 +0x4cd

on commit abb818b

Can be reduced to {{ . | html.y}}.
Mailed CL 10340 to fix it.

CL https://golang.org/cl/10340 mentions this issue.