[TYPO3-core] RFC #11361: Backend TYPO3 AJAX-Interface: json encoded result empty if it contains non-utf-8 characters

Martin Kutschker masi-no at spam-typo3.org
Fri Jun 19 12:07:57 CEST 2009


Benjamin Mack schrieb:
> Hi Masi,
> 
> yes, because I use the variable "requestCharset" that is set in the
> constructor.
> 
> // get charset from current AJAX request (which is expected to be utf-8)
> preg_match('/;\s*charset\s*=\s*([a-zA-Z0-9_-]*)/i',
> $_SERVER['CONTENT_TYPE'], $contenttype);
> $charset = $GLOBALS['LANG']->csConvObj->parse_charset($contenttype[1]);
> if ($charset && $charset != $this->requestCharset) {
>     $this->requestCharset = $charset;
> }
> 
> Well, if it delivers something else than expected then we should set it
> not via this code, right?
> 
> Do you think it's better to hard-code utf-8 in my patch? I'd be happy to
> correct my patch.

No. Sending back data in the same charset as data came in is the way to
go. That is, if it would work.

If we can send data only in utf-8 then I think we should either hardcode
utf-8 or send nothing at all.

BTW, reading the comments on json_decode I read that it suffers form the
same problems. It breaks on anything but utf-8.

To sum up my view:

Check charset of incoming data. Reject anything but utf-8.
Check charset of outgoing data. Convert to UTF-8 (and hope the client
accepts it).

Masi


More information about the TYPO3-team-core mailing list