fix: [unicode] Temporarily escape 4 byte characters until we move the attribute value fields to mb4, fixes #5123

- fixes sync/feed issues related to 4 byte unicode characters
pull/6172/head
iglocska 2020-07-30 09:17:27 +02:00
parent 69c3234005
commit a2c0010d48
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
2 changed files with 18 additions and 1 deletions

View File

@ -2914,7 +2914,23 @@ class AppModel extends Model
if (!is_array($decoded)) {
throw new UnexpectedValueException('JSON must be array type, get ' . gettype($decoded));
}
return $decoded;
}
/*
* Temporary solution for utf8 columns until we migrate to utf8mb4
* via https://stackoverflow.com/questions/16496554/can-php-detect-4-byte-encoded-utf8-chars
*/
public function handle4ByteUnicode($input)
{
return preg_replace(
'%(?:
\xF0[\x90-\xBF][\x80-\xBF]{2}
| [\xF1-\xF3][\x80-\xBF]{3}
| \xF4[\x80-\x8F][\x80-\xBF]{2}
)%xs',
'?',
$input
);
}
}

View File

@ -1467,6 +1467,7 @@ class Attribute extends AppModel
// do some last second modifications before the validation
public function modifyBeforeValidation($type, $value)
{
$value = $this->handle4ByteUnicode($value);
switch ($type) {
case 'md5':
case 'sha1':