在HTML中使用Unescape css输入 [英] Unescape css input in HTML

查看:266
本文介绍了在HTML中使用Unescape css输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用unescape html?

How do I unescape html?

我将一个css文件传入html中,像这样

I'm passing a css file into html like this

<style>{{.file}}</style>

我得到这个

<style>ZgotmplZ</style>

我试着使用template.HTML(data)封装字段,但是没有成功。 / p>

I've tried wrapping the field with template.HTML(data), didn't work.

推荐答案


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

The escaping is contextual, so actions can appear within JavaScript, CSS, and URI contexts.

ZgotmplZ是一个特殊值,如果您尝试的值include在上下文中是无效的或不安全的。

"ZgotmplZ" is a special value, it is used as a replacement if the value you're trying to include is invalid or unsafe in the context.

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

So the problem is the CSS value you're trying to include, it is not safe. Try something simple first and see if it works, like:

body {background-color: #000}

在文档中找到ZgotmplZ ErrorCode ),引用它:

Found the discussion of "ZgotmplZ" in the documentation (at type ErrorCode), quoting it:

Example Template:

<img src="{{.X}}">
where {{.X}} evaluates to `javascript:...`

讨论:

Discussion:

"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:...`).



解决方案



插入是在CSS代码而不是HTML的情况下,你不能/不应该使用 template.HTML(data)

预定义类型 CSS 以安全包含来自可信来源的CSS代码,例如您指定的CSS代码并非来自用户填充的HTML表单。示例:

There is a predefined type CSS for safe inclusion of CSS code coming from trusted source, e.g. CSS code you specify and is not coming from an HTML form filled by the user. Example:

var safeCss = template.CSS(`body {background-image: url("paper.gif");}`)

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

And pass the safeCss value to your template parameter.

这篇关于在HTML中使用Unescape css输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆