Golang html/template.HTMLEscapeString function example

package html/template

HTMLEscapeString returns the escaped HTML equivalent of the plain text data s (1st parameter).

Golang html/template.HTMLEscapeString function usage example

 package main

 import (
 "fmt"
 "html/template"
 )

 func main() {

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

 final := template.HTMLEscapeString(s)

 fmt.Println(final)

 }

Output :

&lt;script&gt;alert(&#39;xss attack!&#39;)&lt;/script&gt;

Reference :

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

Advertisement