Golang html/template.HTMLEscaper function example

package html/template

HTMLEscaper returns the escaped HTML equivalent of the textual representation of its arguments.

Golang html/template.HTMLEscaper function usage example

 package main

 import (
 "fmt"
 "html/template"
 )

 func main() {

 a := "<script>alert('xss attack!')</script>"

 b := "<p>This is a paragraph</p>"

 final := template.HTMLEscaper(a, b)

 fmt.Println(final)

 }

Output :

&lt;script&gt;alert(&#39;xss attack!&#39;)&lt;/script&gt;&lt;p&gt;This is a paragraph&lt;/p&gt;

References :

http://golang.org/pkg/html/template/#HTMLEscaper

Advertisement