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 :
Advertisement
Something interesting
Tutorials
+14.4k Golang : How to convert a number to words
+11.9k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+6.5k Golang : Convert an executable file into []byte example
+17.5k Golang : Linked list example
+18.1k Golang : Check if a directory exist or not
+25.7k Golang : missing Mercurial command
+22.2k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+6.9k Golang : Decode XML data from RSS feed
+5.7k Unix/Linux/MacOSx : Get local IP address
+5.5k Golang : Stop goroutine without channel