mirror of
https://github.com/friendica/friendica
synced 2024-12-22 22:40:16 +00:00
Merge pull request #14457 from annando/length-check
Fix for the string truncation for "latin1" charset
This commit is contained in:
commit
a3dff95c2b
1 changed files with 9 additions and 1 deletions
|
@ -8,7 +8,9 @@
|
|||
namespace Friendica\Database\Definition;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\DI;
|
||||
|
||||
/**
|
||||
* Stores the whole database definition
|
||||
|
@ -65,12 +67,18 @@ class DbaDefinition
|
|||
|
||||
$fields = [];
|
||||
|
||||
$charset = DI::config()->get('database', 'charset') ?? '';
|
||||
|
||||
// Assign all field that are present in the table
|
||||
foreach ($fieldNames as $field) {
|
||||
if (isset($data[$field])) {
|
||||
// Limit the length of varchar, varbinary, char and binary fields
|
||||
if (is_string($data[$field]) && preg_match("/char\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
|
||||
$data[$field] = mb_substr($data[$field], 0, $result[1]);
|
||||
if ($charset == 'latin1') {
|
||||
$data[$field] = substr($data[$field], 0, $result[1]);
|
||||
} else {
|
||||
$data[$field] = mb_substr($data[$field], 0, $result[1]);
|
||||
}
|
||||
} elseif (is_string($data[$field]) && preg_match("/binary\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
|
||||
$data[$field] = substr($data[$field], 0, $result[1]);
|
||||
} elseif (is_numeric($data[$field]) && $definition[$table]['fields'][$field]['type'] === 'int') {
|
||||
|
|
Loading…
Reference in a new issue