Skip to content

Commit 4e5e02a

Browse files
committed
Remove emoji symbols and pictographs from shortname
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 89eda11 commit 4e5e02a

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

controller/manifest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use phpbb\language\language;
1616
use phpbb\path_helper;
1717
use phpbb\user;
18+
use phpbb\webpushnotifications\json\sanitizer as json_sanitizer;
1819
use Symfony\Component\HttpFoundation\JsonResponse;
1920
use Symfony\Component\HttpFoundation\Response;
2021

@@ -65,7 +66,7 @@ public function handle(): JsonResponse
6566

6667
$manifest = [
6768
'name' => $this->config['sitename'],
68-
'short_name' => $this->config['pwa_short_name'] ?: utf8_substr(preg_replace('/[^\x21-\x7E]/', '', html_entity_decode($this->config['sitename'], ENT_QUOTES, 'UTF-8')), 0, 12),
69+
'short_name' => $this->config['pwa_short_name'] ?: utf8_substr(preg_replace('/\s+/', '', json_sanitizer::strip_emoji($this->config['sitename'])), 0, 12),
6970
'display' => 'standalone',
7071
'orientation' => 'portrait',
7172
'dir' => $this->language->lang('DIRECTION'),

event/listener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpbb\template\template;
1919
use phpbb\user;
2020
use phpbb\webpushnotifications\form\form_helper;
21+
use phpbb\webpushnotifications\json\sanitizer as json_sanitizer;
2122
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2223

2324
/**
@@ -353,6 +354,6 @@ protected function can_use_notifications()
353354
*/
354355
protected function get_shortname($name)
355356
{
356-
return utf8_substr(preg_replace('/[^\x20-\x7E]/', '', $name), 0, 12);
357+
return utf8_substr(preg_replace('/\s+/', '', json_sanitizer::strip_emoji($name)), 0, 12);
357358
}
358359
}

json/sanitizer.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,19 @@ public static function decode(string $json) : array
5151
$data = json_decode($json, true);
5252
return !empty($data) ? self::sanitize($data) : [];
5353
}
54+
55+
/**
56+
* Remove emoji from a string
57+
*
58+
* @param string $string
59+
* @return string
60+
*/
61+
public static function strip_emoji(string $string) : string
62+
{
63+
return preg_replace(
64+
'/[\x{1F000}-\x{1F9FF}]|[\x{2600}-\x{27FF}]/u',
65+
'',
66+
html_entity_decode($string, ENT_QUOTES, 'UTF-8')
67+
);
68+
}
5469
}

0 commit comments

Comments
 (0)