Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go HTML中的Unescape css输入_Go_Go Templates - Fatal编程技术网

Go HTML中的Unescape css输入

Go HTML中的Unescape css输入,go,go-templates,Go,Go Templates,如何取消对html的浏览 我将css文件传递到html中,如下所示 <style>{{.file}}</style> {{.file} 我明白了 <style>ZgotmplZ</style> ZgotmplZ 我尝试过用template.HTML(数据)包装该字段,但没有成功。Go HTML模板包正确地删除了CSS。引述: 转义是上下文的,因此操作可以出现在JavaScript、CSS和URI上下文中 “ZgotmplZ”是一个特殊值,如

如何取消对html的浏览

我将css文件传递到html中,如下所示

<style>{{.file}}</style>
{{.file}
我明白了

<style>ZgotmplZ</style>
ZgotmplZ

我尝试过用template.HTML(数据)包装该字段,但没有成功。

Go HTML模板包正确地删除了CSS。引述:

转义是上下文的,因此操作可以出现在JavaScript、CSS和URI上下文中

“ZgotmplZ”
是一个特殊值,如果您试图包含的值在上下文中无效或不安全,则将其用作替换值

所以问题是你试图包含的CSS值,它是不安全的。首先尝试一些简单的方法,看看是否有效,例如:

body {background-color: #000}
在文档(at类型)中找到了关于“ZgotmplZ”的讨论,并引用了它:

“ZgotmplZ”
说明: 示例模板:

<img src="{{.X}}">
where {{.X}} evaluates to `javascript:...`
"ZgotmplZ" is a special value that indicates that unsafe content reached a
CSS or URL context at runtime. The output of the example will be
  <img src="#ZgotmplZ">
If the data comes from a trusted source, use content types to exempt it
from filtering: URL(`javascript:...`).

并将
safeCss
值传递给模板参数。

感谢您向我们展示
template.CSS
。很难找到直接的解决方案。
var safeCss = template.CSS(`body {background-image: url("paper.gif");}`)