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
+5.8k Cash Flow : 50 days to pay your credit card debt
+13k Golang : Get terminal width and height example
+14.6k Golang : GUI with Qt and OpenCV to capture image from camera
+19.9k Golang : Count JSON objects and convert to slice/array
+11.3k Golang : Post data with url.Values{}
+8.9k Golang : Gaussian blur on image and camera video feed examples
+6.7k Golang : Skip or discard items of non-interest when iterating example
+9.7k Random number generation with crypto/rand in Go
+19.9k Golang : Measure http.Get() execution time
+7.7k Gogland : Where to put source code files in package directory for rookie
+5.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+13.8k Golang : Convert spaces to tabs and back to spaces example