Skip to content

Commit d0a0cb7

Browse files
committed
Allow emoji in manifest shortname
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent a30a204 commit d0a0cb7

4 files changed

Lines changed: 3 additions & 38 deletions

File tree

controller/manifest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use phpbb\language\language;
1616
use phpbb\path_helper;
1717
use phpbb\user;
18-
use phpbb\webpushnotifications\json\sanitizer as json_sanitizer;
1918
use Symfony\Component\HttpFoundation\JsonResponse;
2019
use Symfony\Component\HttpFoundation\Response;
2120

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

6766
$manifest = [
6867
'name' => $this->config['sitename'],
69-
'short_name' => $this->config['pwa_short_name'] ?: utf8_substr(preg_replace('/\s+/', '', json_sanitizer::strip_emoji($this->config['sitename'])), 0, 12),
68+
'short_name' => $this->config['pwa_short_name'] ?: utf8_substr(html_entity_decode($this->config['sitename'], ENT_QUOTES, 'UTF-8'), 0, 12),
7069
'display' => 'standalone',
7170
'orientation' => 'portrait',
7271
'dir' => $this->language->lang('DIRECTION'),

event/listener.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
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;
2221
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2322

2423
/**
@@ -226,13 +225,6 @@ public function validate_pwa_options($event)
226225

227226
$short_name = $event['cfg_array']['pwa_short_name'];
228227

229-
// Do not allow emoji
230-
if (preg_match(json_sanitizer::EMOJI_REGEX, $short_name))
231-
{
232-
$this->add_error($event, 'PWA_SHORT_NAME_INVALID');
233-
return;
234-
}
235-
236228
// Do not allow strings longer than 12 characters
237229
if (mb_strlen($short_name, 'UTF-8') > 12)
238230
{
@@ -354,6 +346,6 @@ protected function can_use_notifications()
354346
*/
355347
protected function get_shortname($name)
356348
{
357-
return utf8_substr(preg_replace('/\s+/', '', json_sanitizer::strip_emoji($name)), 0, 12);
349+
return utf8_substr(html_entity_decode($name, ENT_QUOTES, 'UTF-8'), 0, 12);
358350
}
359351
}

json/sanitizer.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,4 @@ public static function decode(string $json) : array
5151
$data = json_decode($json, true);
5252
return !empty($data) ? self::sanitize($data) : [];
5353
}
54-
55-
/**
56-
* regex for emoji
57-
* Basic emoji (U+1F000 to U+1F9FF)
58-
* Transport and map symbols (U+1F680 to U+1F6FF)
59-
* Miscellaneous symbols and pictographs (U+1F300 to U+1F5FF)
60-
* Additional emoji symbols (U+1F600 to U+1F64F)
61-
*
62-
* @var string
63-
*/
64-
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';
65-
66-
/**
67-
* Remove emoji from a string
68-
*
69-
* @param string $string
70-
* @return string
71-
*/
72-
public static function strip_emoji(string $string) : string
73-
{
74-
return preg_replace(
75-
self::EMOJI_REGEX,
76-
'',
77-
html_entity_decode($string, ENT_QUOTES, 'UTF-8')
78-
);
79-
}
8054
}

language/en/webpushnotifications_common_acp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
'PWA_SETTINGS' => 'Progressive web application options',
4242
'PWA_SHORT_NAME' => 'Short site name',
4343
'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 <samp>Site name</samp> will be used.)',
44-
'PWA_SHORT_NAME_INVALID' => '“Short site name” contains illegal characters or exceeds the 12 character limit.',
44+
'PWA_SHORT_NAME_INVALID' => '“Short site name” exceeds the 12 character limit.',
4545
'PWA_ICON_SMALL' => 'Small mobile device icon',
4646
'PWA_ICON_SMALL_EXPLAIN' => 'File name of a 192px x 192px PNG image. This file must be uploaded to your board’s <samp>icons</samp> directory.',
4747
'PWA_ICON_LARGE' => 'Large mobile device icon',

0 commit comments

Comments
 (0)