Golang text/template.JSEscapeString() function example

package text/template

Golang text/template.JSEscapeString() function usage example

 package main

 import (
  "fmt"
  "text/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/text/template/#JSEscapeString

Advertisement