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
+25.3k Golang : Convert uint value to string type
+7.6k Javascript : Push notifications to browser with Push.js
+6.5k Golang : Combine slices of complex numbers and operation example
+8.6k Android Studio : Import third-party library or package into Gradle Scripts
+8.8k Golang : Accept any number of function arguments with three dots(...)
+7.7k Golang : get the current working directory of a running program
+11.5k CodeIgniter : Import Linkedin data
+28.6k Get file path of temporary file in Go
+19.4k Golang : How to count the number of repeated characters in a string?
+21.8k Golang : How to reverse slice or array elements order
+9.3k Golang : How to get username from email address
+10.2k Golang : Use regular expression to get all upper case or lower case characters example