#CCCCCC
) or rgb color (rgb(100,100,100)
) formulas as well as plain-text well-known color keywords (blue
) - this is drastically different than what would go into something like say the width property - which would simply be a fixed size or percentage. It was at this point that we came to the conclusion that jquery-encoder should use the property name that is being encoded for to determine the correct escaping syntax. The new API for the property aware encodeForXXX methods follows
encodeForCss(property,data,omitPropertyName)
Returns the encodedproperty: value
pair, escaped in the context of the passed in property. Banned properties are thebehavior
family (behavior,-moz-behavior,-ms-behavior) as they are not safe to be set using untrusted data and allow for script injection by definition. Values that contain the expression keyword will also be rejected as unsafe, as this is the equivelent of calling the javascripteval
within a style context. If the optionalomitPropertyName
istrue
the function will return only thevalue
encoded for the passed in property.
encodeForHTMLAttribute(attribute,data,omitAttributeName)
Returns the encodedattribute="value"
pair, escaped in the context of the passed in attribute. Banned attributes arehref
andsrc
as those should be encoded using theencodeForUrl
function. The javascript event hookson*
are also banned as they should be set using theencodeForJavascript
function. Thestyle
attribute should be set using theencodeForCSS
function. If the optionalomitAttributeName
parameter is true, the function will return only thevalue
encoded for the passed in attribute.
In all cases, the property/attribute names are canonicalized prior to encoding to validate and get the escaping context for that property (or the default if there is no specific context specified)
This was a somewhat difficult decision to make, simply because it is mixing in a bit of validation with the output encoding control - which is not necessarily ideal from a pure design standpoint. I felt however, that this was a necessary evil in order to ensure correct encoding/escaping context and get the most value from the plugin.
Please continue to send me your thoughts and ideas for the plugin - I plan on releasing it to the general public through the jQuery plugin repository within the next couple weeks so any feedback from the community leading up to the release of the plugin will only make it stronger!
As always, the latest version of the plugin is available from my github
https://github.com/chrisisbeef/jquery-encoder
The sandbox (which will be updated with the latest version today) is available on my site:
http://software.digital-ritual.net/jqencoder/
No comments:
Post a Comment