Golang html/template.JSEscaper function example

package html/template

JSEscaper returns the escaped JavaScript equivalent of the textual representation of its arguments.

Golang html/template.JSEscaper function usage example

 package main

 import (
 "fmt"
 "html/template"
 )

 func main() {

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

 b := "<script>alert('javascript')</script>"

 final := template.HTMLEscaper(a, b)

 fmt.Println(final)

 }

Output :

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

&lt;script&gt;alert(&#39;javascript&#39;)&lt;/script&gt;

Reference :

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

Advertisement