Oct. 13, 2006, 07:07 AM
Determining the attribute quote character to use in a web filters replacement text seems like it ought to be easy. Just use the double quote character (").However, javascript throws a monkey wrench into the picture.
When a web filter matches inside js, using the wrong attribute quote in the replacement text will break the js. This is because the html tag attribute delimiter characters are the same as javascripts string delimiter characters.
When js is involved, looking at a single attribute to determine the quote character often fails. In js, it is not uncommon for one attribute to have a single quote while another uses a double quote. Using the wrong one at the wrong place in the relacement text will break the js.
The approach this code takes is to examine the filters matching text in it's entirety. The matching code looks for telltale signs of javascript in the matching text. If present, the code returns \\" as the attribute quote. This is always safe for use inside js.
If no js is detected, the matching code looks for an attribute name and matches the quote charater that is used. If the web filter matched inside a js string, this shouldn't break it.
Finally, if all else fails, the code returns the double quote character. This is HTML & XHTML friendly.
The code is implemented in a $LST and can be thought of as a function call. To use it in a web filter, just call the list as the last line of the matching expression. Technically, the list never matches, as to avoid filling log window.
I've tried posting the code using the boards php & code tags but it doesn't display correctly. Therefore, I've attached it.
As usual, I'm looking for comments & ideas on how to improve the code.
Mike
When a web filter matches inside js, using the wrong attribute quote in the replacement text will break the js. This is because the html tag attribute delimiter characters are the same as javascripts string delimiter characters.
When js is involved, looking at a single attribute to determine the quote character often fails. In js, it is not uncommon for one attribute to have a single quote while another uses a double quote. Using the wrong one at the wrong place in the relacement text will break the js.
The approach this code takes is to examine the filters matching text in it's entirety. The matching code looks for telltale signs of javascript in the matching text. If present, the code returns \\" as the attribute quote. This is always safe for use inside js.
If no js is detected, the matching code looks for an attribute name and matches the quote charater that is used. If the web filter matched inside a js string, this shouldn't break it.
Finally, if all else fails, the code returns the double quote character. This is HTML & XHTML friendly.
The code is implemented in a $LST and can be thought of as a function call. To use it in a web filter, just call the list as the last line of the matching expression. Technically, the list never matches, as to avoid filling log window.
I've tried posting the code using the boards php & code tags but it doesn't display correctly. Therefore, I've attached it.
As usual, I'm looking for comments & ideas on how to improve the code.
Mike