Comments within style= attributes - safe?

别来无恙 提交于 2019-12-11 10:21:39

问题


I am working on a CMS that generates CSS "style='xyz'" statements from user input. The user input will be validated but as an additional safeguard, I want to check the validity of the values on generation of the CSS code.

If an invalid value is encountered - e.g. a relative width ("50%") where only absolute values are allowed due to layout restrictions - I would like to return a comment INSIDE the style attribute to help debugging:

<div class="content" style="background-color: lightblue; /* WIDTH was invalid: Only absolute values allowed here */; border: 1px orange dotted;">

Is this "safe", i.e. will all major browsers still parse the settings before and after the comment properly? It is difficult to Google information about this.


回答1:


It is probably safe but I wouldn't put the wrong values commented into the markup.

Let the user know they did something wrong in the very beginning before you generate markup.

A good idea would be to create such a test case and feed it to the W3C validator to see what it would say says about it.

http://validator.w3.org/




回答2:


From the top of my head, IE supports it, Fx doesn't.



来源:https://stackoverflow.com/questions/1612909/comments-within-style-attributes-safe

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