Golang html/template.JSEscapeString function example

package html/template

JSEscapeString returns the escaped JavaScript equivalent of the plain text data s(1st parameter).

Golang html/template.JSEscapeString function usage example

 package main

 import (
 "fmt"
 "html/template"
 )

 func main() {

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

 final := template.JSEscapeString(s)

 fmt.Println(final)

 }

Output :

\x3Cscript\x3Ealert(\'xss attack!\')\x3C/script\x3E

Reference :

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

Advertisement