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.7k Golang : Calculations using complex numbers example
+18.4k Golang : Logging with logrus
+9.9k Golang : Translate language with language package example
+21.8k Golang : Convert string slice to struct and access with reflect example
+17k Golang : How to save log messages to file?
+37.5k Golang : Converting a negative number to positive number
+8.2k How to show different content from website server when AdBlock is detected?
+7.2k Golang : Use modern ciphers only in secure connection
+8.6k Golang : Progress bar with ∎ character
+12.3k Golang : How to display image file or expose CSS, JS files from localhost?
+16.5k Golang : File path independent of Operating System
+51.4k Golang : Check if item is in slice/array