Golang html.UnescapeString function example

package html

UnescapeString unescapes entities like "<" to become "<". It unescapes a larger range of entities than EscapeString escapes. For example, "á" unescapes to "á", as does "á" and "&xE1;". UnescapeString(EscapeString(s)) == s always holds, but the converse isn't always true.

Golang html.UnescapeString function usage example

 package main

 import (
 "fmt"
 "html"
 )

 func main() {
 s := "&lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;"
 fmt.Println(html.UnescapeString(s))
 }

Output :

Reference :

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

Advertisement