Correctly truncate multibyte strings to fit into the database

Closes: #26174

Signed-off-by: Chih-Hsuan Yen <yan12125@gmail.com>
This commit is contained in:
Chih-Hsuan Yen 2021-04-26 16:05:50 +08:00
parent bf9ed2d3cd
commit fea5b4a8b9
No known key found for this signature in database
GPG Key ID: F98EF2A7B0A098AE
2 changed files with 4 additions and 4 deletions

View File

@ -2678,7 +2678,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
if (!$this->db->supports4ByteText()) {
$value = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value);
}
$value = mb_substr($value, 0, 254);
$value = mb_strcut($value, 0, 254);
$query->setParameter('name', $property->name);
$query->setParameter('parameter', null);
@ -2698,8 +2698,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
}
$query->setParameter('name', $property->name);
$query->setParameter('parameter', mb_substr($key, 0, 254));
$query->setParameter('value', mb_substr($value, 0, 254));
$query->setParameter('parameter', mb_strcut($key, 0, 254));
$query->setParameter('value', mb_strcut($value, 0, 254));
$query->executeUpdate();
}
}

View File

@ -1271,7 +1271,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
}
}
$query->setParameter('name', $property->name);
$query->setParameter('value', mb_substr($property->getValue(), 0, 254));
$query->setParameter('value', mb_strcut($property->getValue(), 0, 254));
$query->setParameter('preferred', $preferred);
$query->execute();
}