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
+11.6k Golang : Surveillance with web camera and OpenCV
+12.8k Golang : http.Get example
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+10.2k Golang : Text file editor (accept input from screen and save to file)
+9.2k Golang : Create and shuffle deck of cards example
+26.6k Golang : Encrypt and decrypt data with AES crypto
+7.8k Golang : Scan files for certain pattern and rename part of the files
+4.6k Mac OSX : Get disk partitions' size, type and name
+8.3k Swift : Convert (cast) Character to Integer?
+10.2k Golang : Check a web page existence with HEAD request example
+20.9k PHP : Convert(cast) int to double/float
+16.5k Golang : Execute terminal command to remote machine example