Golang html.EscapeString function example

package html

EscapeString escapes special characters like "<" to become "<". It escapes only five such characters: <, >, &, ' and ". UnescapeString(EscapeString(s)) == s always holds, but the converse isn't always true.

Golang html.EscapeString function usage example

 package main

 import (
 "fmt"
 "html"
 )

 func main() {
 s := "<script>alert('xss')</script>"
 fmt.Println(html.EscapeString(s))
 }

Output :

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

Reference :

http://golang.org/pkg/html/#EscapeString

Advertisement