Why am I seeing ZgotmplZ in my Go HTML template output?

后端 未结 6 976
执念已碎
执念已碎 2020-12-10 23:31

When I\'m calling a Go template function to output HTML, it displays ZgotmplZ.

Sample code:

http://play.golang.org/p/tfuJa_pFkm

         


        
6条回答
  •  生来不讨喜
    2020-12-11 00:26

    You should wrap the string in an HTMLAttr, which was designed for text that gets injected in between angle brackets. Per the documentation:

    https://golang.org/pkg/html/template/#HTMLAttr

    HTMLAttr encapsulates an HTML attribute from a trusted source, for example,  dir="ltr".

    Use of this type presents a security risk: the encapsulated content should come from a trusted source, as it will be included verbatim in the template output.

    type HTMLAttr string

提交回复
热议问题