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
+19.4k Golang : Fix cannot download, $GOPATH not set error
+5.2k Golang : Convert lines of string into list for delete and insert operation
+5.9k Golang : Use NLP to get sentences for each paragraph example
+10.8k Android Studio : Checkbox for user to select options example
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+13.5k Golang : Count number of runes in string
+6.3k Golang : Test input string for unicode example
+17k Golang : Get number of CPU cores
+9.4k Golang : Generate EAN barcode
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+11k Golang : Create S3 bucket with official aws-sdk-go package
+9.4k Golang : How to protect your source code from client, hosting company or hacker?