Skip to content

Commit 8787b24

Browse files
committed
Remove multibyte characters from short names
Signed-off-by: Matt Friedman <maf675@gmail.com> fix Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent a5c9b6e commit 8787b24

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

event/listener.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function pwa_manifest()
142142
$this->template->assign_vars([
143143
'U_MANIFEST_URL' => $this->controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
144144
'U_TOUCH_ICON' => $this->config['pwa_icon_small'],
145-
'SHORT_SITE_NAME' => $this->config['pwa_short_name'] ?: substr($this->config['sitename'], 0, 12),
145+
'SHORT_SITE_NAME' => $this->config['pwa_short_name'] ?: $this->get_shortname($this->config['sitename']),
146146
]);
147147
}
148148

@@ -252,4 +252,15 @@ protected function can_use_notifications()
252252
&& ANONYMOUS !== $this->user->id()
253253
&& USER_IGNORE !== (int) $this->user->data['user_type'];
254254
}
255+
256+
/**
257+
* Get short name from a string (strip out multibyte characters and trim to 12 characters)
258+
*
259+
* @param string $name
260+
* @return string 12 max characters string
261+
*/
262+
protected function get_shortname($name)
263+
{
264+
return utf8_substr(preg_replace('/[^\x20-\x7E]/', '', $name), 0, 12);
265+
}
255266
}

0 commit comments

Comments
 (0)