hdr-Security_Model (Autoescaping) in Go

Posted by GoDoc
Public (Editable by Users)
Go
Edit
package main

import (
	"log"
	"os"
	"text/template"
)

func main() {
	check := func(err error) {
		if err != nil {
			log.Fatal(err)
		}
	}
	t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
	check(err)
	err = t.ExecuteTemplate(os.Stdout, "T", "<script>alert('you have been pwned')</script>")
	check(err)
}