mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
TextFormat: use mb_scrub() in clean()
this redacts invalid characters to prevent them appearing in places that might break the client.
This commit is contained in:
parent
7a6f279825
commit
8fad5a6e30
@ -25,6 +25,7 @@ namespace pocketmine\utils;
|
||||
|
||||
use function is_array;
|
||||
use function json_encode;
|
||||
use function mb_scrub;
|
||||
use function preg_quote;
|
||||
use function preg_replace;
|
||||
use function preg_split;
|
||||
@ -77,14 +78,15 @@ abstract class TextFormat{
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the string from Minecraft codes and ANSI Escape Codes
|
||||
* Cleans the string from Minecraft codes, ANSI Escape Codes and invalid UTF-8 characters
|
||||
*
|
||||
* @param string $string
|
||||
* @param bool $removeFormat
|
||||
*
|
||||
* @return string
|
||||
* @return string valid clean UTF-8
|
||||
*/
|
||||
public static function clean(string $string, bool $removeFormat = true) : string{
|
||||
$string = mb_scrub($string, 'UTF-8');
|
||||
if($removeFormat){
|
||||
return str_replace(TextFormat::ESCAPE, "", preg_replace(["/" . TextFormat::ESCAPE . "[0-9a-fk-or]/u", "/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/"], "", $string));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user