From ae6a18c31d73cefd3eb68b6ca98a44432b391e02 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 4 Dec 2019 08:29:30 +0100 Subject: Fix cutting of multibyte characters Signed-off-by: Joas Schilling --- lib/Push.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Push.php b/lib/Push.php index bc25486..810a003 100644 --- a/lib/Push.php +++ b/lib/Push.php @@ -264,9 +264,10 @@ class Push { // Max length of encryption is 255, so we need to shorten the subject to be shorter $subject = $notification->getParsedSubject(); - $dataLength = 245 - strlen(json_encode($data)); + // Half the length for multibyte characters like Russian, Chinese, Japanese, Emojis, … + $dataLength = floor((245 - strlen(json_encode($data))) / 2) - 1; if (strlen($subject) > $dataLength) { - $data['subject'] = substr($subject, 0, $dataLength) . '…'; + $data['subject'] = mb_substr($subject, 0, $dataLength) . '…'; } else { $data['subject'] = $subject; } -- cgit v1.2.3