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.4k Golang : Sort and reverse sort a slice of runes
+9.1k Golang : ffmpeg with os/exec.Command() returns non-zero status
+23.9k Golang : Time slice or date sort and reverse sort example
+6.3k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+10.9k Golang : Byte format example
+13.7k Golang : Get uploaded file name or access uploaded files
+6.7k Golang : Array mapping with Interface
+7k Golang : How to stop user from directly running an executable file?
+8.1k Golang : Progress bar with ∎ character
+9.6k Golang : Test a slice of integers for odd and even numbers
+21.3k Golang : Join arrays or slices example
+5.4k Golang : Grab news article text and use NLP to get each paragraph's sentences