[TYPO3-dev] Characters are badly encoded in form validation JavaScript

Martin Kutschker masi-no at spam-typo3.org
Fri Mar 27 12:22:15 CET 2009


Francois Suter schrieb:
> Hi all,
> 
> The problem mentioned in the subject has been reported at least 6 times
> to the bug tracker ([1]-[6]). The issue happens in TYPO3's mail form.
> Take a site encoded in UTF-8 and create a field with a name such as
> "Prénom" or "Übergeek". If that field fails validation (for whatever
> reason, e.g. it is required and you left it empty) you will get a JS
> alert window with the special characters misinterpreted, because JS
> chokes on UTF-8.
> 
> Based on some suggestions in [1] I have made a patch which fixes the
> issue, but it converts field names explicitly to iso-8859-1 and I
> suspect this will not work for non-latin based languages. So I'm not
> sure the decoding can really be done server-side. But is there any
> solution client-side?

Sure, don't use escape(). Modern browsers convert any data to iso-8859-1
before escape'ing. Actually I think you don't need escape() nowadays at
all as browsers have fairly good character set support in their JS engines.

If you must encode strings then use encodeURI (don't recall the exact
name), but this function converts the data to UTF8. So depending on the
context and local charset you must en/decode from or to UTF8 PHP.
Besides that, really old browsers don't know this function.

Masi




More information about the TYPO3-dev mailing list