Skip to content

Commit a30a204

Browse files
committed
Use emoji regex as constant
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 5a0c6c7 commit a30a204

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

event/listener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function validate_pwa_options($event)
227227
$short_name = $event['cfg_array']['pwa_short_name'];
228228

229229
// Do not allow emoji
230-
if (preg_match('/[\x{1F000}-\x{1F9FF}]|[\x{2600}-\x{27FF}]|[\x{1F300}-\x{1F64F}]|[\x{1F680}-\x{1F6FF}]|[\x{2700}-\x{27BF}]|[\x{FE00}-\x{FE0F}]/u', $short_name))
230+
if (preg_match(json_sanitizer::EMOJI_REGEX, $short_name))
231231
{
232232
$this->add_error($event, 'PWA_SHORT_NAME_INVALID');
233233
return;

json/sanitizer.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,26 @@ public static function decode(string $json) : array
5353
}
5454

5555
/**
56-
* Remove emoji from a string
57-
* Basic emoji (U+1F300 to U+1F64F)
56+
* regex for emoji
57+
* Basic emoji (U+1F000 to U+1F9FF)
5858
* Transport and map symbols (U+1F680 to U+1F6FF)
5959
* Miscellaneous symbols and pictographs (U+1F300 to U+1F5FF)
6060
* Additional emoji symbols (U+1F600 to U+1F64F)
6161
*
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+
*
6269
* @param string $string
6370
* @return string
6471
*/
6572
public static function strip_emoji(string $string) : string
6673
{
6774
return preg_replace(
68-
'/[\x{1F000}-\x{1F9FF}]|[\x{2600}-\x{27FF}]|[\x{1F300}-\x{1F64F}]|[\x{1F680}-\x{1F6FF}]/u',
75+
self::EMOJI_REGEX,
6976
'',
7077
html_entity_decode($string, ENT_QUOTES, 'UTF-8')
7178
);

0 commit comments

Comments
 (0)