Skip to content

Commit

Permalink
Allow emoji in manifest shortname
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Friedman <[email protected]>
  • Loading branch information
iMattPro committed Dec 4, 2024
1 parent a30a204 commit d0a0cb7
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 38 deletions.
3 changes: 1 addition & 2 deletions controller/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'),
Expand Down
10 changes: 1 addition & 9 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}
26 changes: 0 additions & 26 deletions json/sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
}
}
2 changes: 1 addition & 1 deletion language/en/webpushnotifications_common_acp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <samp>Site name</samp> 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 <samp>icons</samp> directory.',
'PWA_ICON_LARGE' => 'Large mobile device icon',
Expand Down

0 comments on commit d0a0cb7

Please sign in to comment.