Skip to content

Commit

Permalink
Fix cutting of multibyte characters
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen authored and Backportbot committed Dec 4, 2019
1 parent f46f766 commit 550d325
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ protected function encryptAndSign(Key $userKey, array $device, int $id, INotific

// 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;
}
Expand Down

0 comments on commit 550d325

Please sign in to comment.