HTML:我应该编码大于还是不是? (>>) [英] HTML: Should I encode greater than or not? ( > > )
本文介绍了HTML:我应该编码大于还是不是? (>>)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在编码可能不安全的数据时,是否有理由编码>
?
When encoding possibly unsafe data, is there a reason to encode >
?
- 它可以验证。
- 浏览器解释相同的方式(在
attr =data
的情况下,attr ='data'
,< tag> data< / tag>
)
- It validates either way.
- The browser interprets the same either way, (In the cases of
attr="data"
,attr='data'
,<tag>data</tag>
)
这样做
- 简化基于正则表达式的标签删除。 c code code code code code code code <数据。 : - o (不会发生!)
- 代码中的美学。 (那么什么?)
- To simplify regex based tag removal.
<[^>]+>?
(rare) - Non-quoted strings
attr=data
. :-o (not happening!) - Aesthetics in the code. (so what?)
我没有任何东西?
推荐答案
严格来说,为了防止HTML注入,您只需要将<
编码为& lt;
。
Strictly speaking, to prevent HTML injection, you need only encode <
as <
.
如果用户输入将被放入一个属性中,还将编码为
& quot;
。
If user input is going to be put in an attribute, also encode "
as "
.
如果您正确地使用正确的引用属性,您不需要担心>
。但是,如果你不确定这一点,你应该编码它只是为了安心,它不会有任何伤害。
If you're doing things right and using properly quoted attributes, you don't need to worry about >
. However, if you're not certain of this you should encode it just for peace of mind - it won't do any harm.
这篇关于HTML:我应该编码大于还是不是? (>>)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文