Skip to content

Commit

Permalink
Merge pull request #499 from nextcloud/backport/496/stable17
Browse files Browse the repository at this point in the history
[stable17] Fix cutting of multibyte characters
  • Loading branch information
rullzer authored Dec 4, 2019
2 parents f46f766 + 550d325 commit 7b909fd
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 7b909fd

Please sign in to comment.