chrisboulton/php-resque — Issue #39: Accents/special characters in payloads causing problems 
Author: RVN-BR
Created: 2012-02-01 23:01:04+00:00
State: open

Due to the way that JSON_ENCODE works, accents and some other special characters cause it to return null variables.

This poses a problem when passing messages that include these characters such as text in foreign languages and perhaps more... One work-around for this is to UTF8 encode all of the payload data.

I have tried this in development and it works fine. Is there any downside that you guys can point?

The function I am using was obtained in the php manpages and I havent even tweaked it yet, but the idea is to add something such as:

´´´php
public static function array_utf8_encode_recursive($dat)
{ if (is_string($dat)) {
return utf8_encode($dat);
}
if (is_object($dat)) {
$ovs= get_object_vars($dat);
$new=$dat;
foreach ($ovs as $k =>$v) {
$new->$k=self::array_utf8_encode_recursive($new->$k);
}
return $new;
}

if (!is_array($dat)) return $dat;
$ret = array();
foreach($dat as $i=>$d) $ret[$i] = self::array_utf8_encode_recursive($d);
return $ret;
}
´´´
and then encode the payload through this function (in order to retain the array structure).

I currently identified that this is necessary in resque.php (function push), in job.php (crica line 250) and worker.php (crica line 500)

Another idea is to UTF8 before sneding to resque (which I will do tomorrow for compatibility sakes since I use a "enque wrapper function" in my app). but I thought I'd contirbute this anyhow in case anyone has issues.