Golang text/template.HTMLEscape() function example

package text/template

Golang text/template.HTMLEscape() function usage example

 package main

 import (
  "bytes"
  "fmt"
  "text/template"
 )

 func main() {

  w := bytes.NewBufferString("")

  b := []byte("<script>alert('xss attack!')</script>")

  template.HTMLEscape(w, b)

  fmt.Println(w)

 }

References :

http://golang.org/pkg/text/template/#HTMLEscape

https://www.socketloop.com/references/golang-html-template-htmlescape-function-example

Advertisement