HTML: Should I encode greater than or not? ( > > )

后端 未结 6 677
梦如初夏
梦如初夏 2020-12-05 09:20

When encoding possibly unsafe data, is there a reason to encode >?

  • It validates either way.
  • The browser interprets the same either way
6条回答
  •  -上瘾入骨i
    2020-12-05 10:05

    Strictly speaking, to prevent HTML injection, you need only encode < as <.

    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.

提交回复
热议问题