问题
I was looking through the Underscore.js api and I noticed that _.escape
escapes &
, <
, >
, "
, '
, and /
characters. What surprised me was escaping /
.
Is there a reason to escape /
characters that I don't know about?
回答1:
EDIT: Alright, apparently, it is recommended by OWASP as it "helps end a HTML entity".
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&, <, >, ", '), the forward slash is included as it helps to end an HTML entity.
& --> &
< --> <
> --> >
" --> "
' --> ' ' is not recommended
/ --> / forward slash is included as it helps end an HTML entity
来源:https://stackoverflow.com/questions/8298274/why-does-escape-modify-characters-in-underscore-js