Skip to content

Commit f22aba3

Browse files
committed
Fix quotes in html decode entities uses
1 parent 638d338 commit f22aba3

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

controller/manifest.php

+3-2
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\ext;
1819
use Symfony\Component\HttpFoundation\JsonResponse;
1920
use Symfony\Component\HttpFoundation\Response;
2021

@@ -64,8 +65,8 @@ public function handle(): JsonResponse
6465
$board_url = generate_board_url();
6566

6667
// Emoji fixer-uppers
67-
$sitename = html_entity_decode($this->config['sitename'], ENT_QUOTES, 'UTF-8');
68-
$pwa_short_name = html_entity_decode($this->config['pwa_short_name'], ENT_QUOTES, 'UTF-8');
68+
$sitename = ext::decode_entities($this->config['sitename'], ENT_QUOTES);
69+
$pwa_short_name = ext::decode_entities($this->config['pwa_short_name'], ENT_QUOTES);
6970

7071
$manifest = [
7172
'name' => $sitename,

event/listener.php

+3-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use phpbb\notification\manager;
1818
use phpbb\template\template;
1919
use phpbb\user;
20+
use phpbb\webpushnotifications\ext;
2021
use phpbb\webpushnotifications\form\form_helper;
2122
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2223

@@ -210,7 +211,7 @@ public function pwa_icon_name($value, $key)
210211
*/
211212
public function pwa_short_sitename($value, $key)
212213
{
213-
$placeholder = $this->trim_shortname($this->decode_entities($this->config['sitename']));
214+
$placeholder = $this->trim_shortname(ext::decode_entities($this->config['sitename']));
214215

215216
return '<input id="' . $key . '" type="text" size="40" maxlength="12" name="config[' . $key . ']" value="' . $value . '" placeholder="' . $placeholder . '">';
216217
}
@@ -242,7 +243,7 @@ public function validate_pwa_options($event)
242243
return;
243244
}
244245

245-
$short_name = $this->decode_entities($event['cfg_array']['pwa_short_name']);
246+
$short_name = ext::decode_entities($event['cfg_array']['pwa_short_name'], ENT_QUOTES);
246247

247248
// Do not allow strings longer than 12 characters
248249
if (utf8_strlen($short_name) > 12)
@@ -367,15 +368,4 @@ protected function trim_shortname($name)
367368
{
368369
return utf8_substr($name, 0, 12);
369370
}
370-
371-
/**
372-
* Decode entities, used primarily to fix emoji for display
373-
*
374-
* @param $text
375-
* @return string Decoded string
376-
*/
377-
protected function decode_entities($text)
378-
{
379-
return html_entity_decode($text, ENT_QUOTES, 'UTF-8');
380-
}
381371
}

ext.php

+13
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,17 @@ protected function result()
124124

125125
return false;
126126
}
127+
128+
/**
129+
* Decode entities, used primarily to fix emoji for display
130+
*
131+
* @param string $text
132+
* @param int $flags Uses ENT_NOQUOTES to leave single and double quotes encoded by default
133+
* @param string $encoding
134+
* @return string Decoded string
135+
*/
136+
public static function decode_entities($text, $flags = ENT_NOQUOTES, $encoding = 'UTF-8')
137+
{
138+
return html_entity_decode($text, $flags, $encoding);
139+
}
127140
}

ucp/controller/webpush.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use phpbb\exception\http_exception;
1717
use phpbb\language\language;
1818
use phpbb\notification\manager;
19+
use phpbb\webpushnotifications\ext;
1920
use phpbb\webpushnotifications\form\form_helper;
2021
use phpbb\webpushnotifications\json\sanitizer as json_sanitizer;
2122
use phpbb\path_helper;
@@ -240,8 +241,8 @@ private function get_notification_data(string $notification_data): string
240241

241242
return json_encode([
242243
'heading' => $this->config['sitename'],
243-
'title' => strip_tags(html_entity_decode($notification->get_title(), ENT_NOQUOTES, 'UTF-8')),
244-
'text' => strip_tags(html_entity_decode($notification->get_reference(), ENT_NOQUOTES, 'UTF-8')),
244+
'title' => strip_tags(ext::decode_entities($notification->get_title())),
245+
'text' => strip_tags(ext::decode_entities($notification->get_reference())),
245246
'url' => htmlspecialchars_decode($notification->get_url()),
246247
'avatar' => $this->prepare_avatar($notification->get_avatar()),
247248
]);

0 commit comments

Comments
 (0)