Golang html/template.HTMLEscape function example
package html/template
HTMLEscape writes to w(1st parameter) the escaped HTML equivalent of the plain text data b(2nd parameter).
Golang html/template.HTMLEscape function usage example
package main
import (
"bytes"
"fmt"
"html/template"
)
func main() {
w := bytes.NewBufferString("")
b := []byte("<script>alert('xss attack!')</script>")
template.HTMLEscape(w, b)
fmt.Println(w)
}
Output :
<script>alert('xss attack!')</script>
Reference :
Advertisement
Something interesting
Tutorials
+7.3k Golang : Not able to grep log.Println() output
+8.3k Golang : Auto-generate reply email with text/template package
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+16.6k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+30.4k Golang : How to verify uploaded file is image or allowed file types
+20k Golang : How to run your code only once with sync.Once object
+9k Golang : Go as a script or running go with shebang/hashbang style
+19.1k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+9.3k Golang : Timeout example
+21.8k Golang : How to reverse slice or array elements order
+20.7k Golang : Read directory content with os.Open
+10.6k Golang : Get local time and equivalent time in different time zone