From d0a0cb7f568690813c5fdd0359d1fdfdcd3e8398 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 4 Dec 2024 07:48:29 -0800 Subject: [PATCH] Allow emoji in manifest shortname Signed-off-by: Matt Friedman --- controller/manifest.php | 3 +-- event/listener.php | 10 +------ json/sanitizer.php | 26 ------------------- .../en/webpushnotifications_common_acp.php | 2 +- 4 files changed, 3 insertions(+), 38 deletions(-) diff --git a/controller/manifest.php b/controller/manifest.php index f281813..39c4576 100644 --- a/controller/manifest.php +++ b/controller/manifest.php @@ -15,7 +15,6 @@ use phpbb\language\language; use phpbb\path_helper; use phpbb\user; -use phpbb\webpushnotifications\json\sanitizer as json_sanitizer; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -66,7 +65,7 @@ public function handle(): JsonResponse $manifest = [ 'name' => $this->config['sitename'], - 'short_name' => $this->config['pwa_short_name'] ?: utf8_substr(preg_replace('/\s+/', '', json_sanitizer::strip_emoji($this->config['sitename'])), 0, 12), + 'short_name' => $this->config['pwa_short_name'] ?: utf8_substr(html_entity_decode($this->config['sitename'], ENT_QUOTES, 'UTF-8'), 0, 12), 'display' => 'standalone', 'orientation' => 'portrait', 'dir' => $this->language->lang('DIRECTION'), diff --git a/event/listener.php b/event/listener.php index 1459250..c602db1 100644 --- a/event/listener.php +++ b/event/listener.php @@ -18,7 +18,6 @@ use phpbb\template\template; use phpbb\user; use phpbb\webpushnotifications\form\form_helper; -use phpbb\webpushnotifications\json\sanitizer as json_sanitizer; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -226,13 +225,6 @@ public function validate_pwa_options($event) $short_name = $event['cfg_array']['pwa_short_name']; - // Do not allow emoji - if (preg_match(json_sanitizer::EMOJI_REGEX, $short_name)) - { - $this->add_error($event, 'PWA_SHORT_NAME_INVALID'); - return; - } - // Do not allow strings longer than 12 characters if (mb_strlen($short_name, 'UTF-8') > 12) { @@ -354,6 +346,6 @@ protected function can_use_notifications() */ protected function get_shortname($name) { - return utf8_substr(preg_replace('/\s+/', '', json_sanitizer::strip_emoji($name)), 0, 12); + return utf8_substr(html_entity_decode($name, ENT_QUOTES, 'UTF-8'), 0, 12); } } diff --git a/json/sanitizer.php b/json/sanitizer.php index 2ea9890..b8cd3b0 100644 --- a/json/sanitizer.php +++ b/json/sanitizer.php @@ -51,30 +51,4 @@ public static function decode(string $json) : array $data = json_decode($json, true); return !empty($data) ? self::sanitize($data) : []; } - - /** - * regex for emoji - * Basic emoji (U+1F000 to U+1F9FF) - * Transport and map symbols (U+1F680 to U+1F6FF) - * Miscellaneous symbols and pictographs (U+1F300 to U+1F5FF) - * Additional emoji symbols (U+1F600 to U+1F64F) - * - * @var string - */ - public const EMOJI_REGEX = '/[\x{1F000}-\x{1F9FF}]|[\x{2600}-\x{27FF}]|[\x{1F300}-\x{1F64F}]|[\x{1F680}-\x{1F6FF}]|[\x{1F600}-\x{1F64F}]/u'; - - /** - * Remove emoji from a string - * - * @param string $string - * @return string - */ - public static function strip_emoji(string $string) : string - { - return preg_replace( - self::EMOJI_REGEX, - '', - html_entity_decode($string, ENT_QUOTES, 'UTF-8') - ); - } } diff --git a/language/en/webpushnotifications_common_acp.php b/language/en/webpushnotifications_common_acp.php index 27aac0c..4e408ef 100644 --- a/language/en/webpushnotifications_common_acp.php +++ b/language/en/webpushnotifications_common_acp.php @@ -41,7 +41,7 @@ 'PWA_SETTINGS' => 'Progressive web application options', 'PWA_SHORT_NAME' => 'Short site name', 'PWA_SHORT_NAME_EXPLAIN' => 'Your site name in 12 characters or fewer, which may be used as a label for an icon on a mobile device’s home screen. (If this field is left empty, the first 12 characters of the Site name will be used.)', - 'PWA_SHORT_NAME_INVALID' => '“Short site name” contains illegal characters or exceeds the 12 character limit.', + 'PWA_SHORT_NAME_INVALID' => '“Short site name” exceeds the 12 character limit.', 'PWA_ICON_SMALL' => 'Small mobile device icon', 'PWA_ICON_SMALL_EXPLAIN' => 'File name of a 192px x 192px PNG image. This file must be uploaded to your board’s icons directory.', 'PWA_ICON_LARGE' => 'Large mobile device icon',