Golang text/template.JSEscaper() function example

package text/template

Golang text/template.JSEscaper() function usage example.

 package main

 import (
  "fmt"
  "text/template"
 )

 func main() {

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

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

  final := template.HTMLEscaper(a, b)

  fmt.Println(final)

 }

Output :

<script>alert('xss!')</script><script>alert('javascript')</script>

Reference :

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

Advertisement