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

后端 未结 6 685
梦如初夏
梦如初夏 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条回答
  •  生来不讨喜
    2020-12-05 09:54

    Current browsers' HTML parsers have no problems with uquoted >s

    However, unfortunately, using regular expressions to "parse" HTML in JS is pretty common. (example: Ext.util.Format.stripTags). Also poorly written command line tools, IDEs, or Java classes etc. may not be sophisticated enough to determine the limiter of an opening tag.

    So, you may run into problems with code like this:

    
    

    (Note how the syntax highlighter treats this snippet!)

提交回复
热议问题