Is it necessary to html encode right angle brackets?

丶灬走出姿态 提交于 2019-12-23 16:08:40

问题


I'm adding some meta description data to my header like so:

HtmlMeta meta = new HtmlMeta();
meta.Name = "description";
meta.Content = description; // this is unencoded
page.Header.Controls.Add(meta);

And .net helpfully encodes things like & and <, but not >. Now, I can't imagine that this would be an oversight, so I conclude that it's unnecessary to escape them. But before I go back to the client with that answer, it would be nice to get confirmation by Some Strangers From The Intarwebs first :)


回答1:


According to the XML specification > is indeed valid for attributes. Only <, & and " or ' need escaping.

[10]    AttValue    ::=    '"' ([^<&"] | Reference)* '"'
                         | "'" ([^<&'] | Reference)* "'"


来源:https://stackoverflow.com/questions/7389867/is-it-necessary-to-html-encode-right-angle-brackets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!