Beware of doubly escaped ampersands

It is not uncommon to see web pages with text showing incorrectly as "blah" instead of "blah". ( A simple search for the text '"' will return numerous examples of such errors.)

This is caused by overzealous escaping of special characters. The ampersand character '&', in particular, is doubly special: it is both a special character, and forms part of the escape mechanism itself, as in '>' and '"'.

If text containing any special character is escaped twice, then the above mentioned problem occurs. A simple example shows why :

The most common cause of such double escaping occurs by : Since the escaping is related to HTML - that is, to the presentation layer - it is recommended that the escaping be performed only in the presentation layer itself, and not in the database.

See Also :
Escape special characters
Beware of common hacks
Would you use this technique?
Yes   No   Undecided   
© 2012 Hirondelle Systems | Source Code | Contact | License | RSS
Individual code snippets can be used under this BSD license - Last updated on August 1, 2010.
Over 180,000 unique IPs last month - Built with WEB4J.
- In Memoriam : Bill Dirani -