mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 02:38:54 +00:00
add some UTF-8 validation
This commit is contained in:
parent
399ef13069
commit
135a2f520c
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block\utils;
|
namespace pocketmine\block\utils;
|
||||||
|
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use function array_fill;
|
use function array_fill;
|
||||||
use function array_pad;
|
use function array_pad;
|
||||||
use function array_slice;
|
use function array_slice;
|
||||||
@ -118,9 +119,7 @@ class SignText{
|
|||||||
*/
|
*/
|
||||||
public function setLine(int $index, string $line) : void{
|
public function setLine(int $index, string $line) : void{
|
||||||
$this->checkLineIndex($index);
|
$this->checkLineIndex($index);
|
||||||
if(!mb_check_encoding($line, 'UTF-8')){
|
Utils::checkUTF8($line);
|
||||||
throw new \InvalidArgumentException("Line must be valid UTF-8 text");
|
|
||||||
}
|
|
||||||
if(strpos($line, "\n") !== false){
|
if(strpos($line, "\n") !== false){
|
||||||
throw new \InvalidArgumentException("Line must not contain newlines");
|
throw new \InvalidArgumentException("Line must not contain newlines");
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ use pocketmine\nbt\tag\StringTag;
|
|||||||
use pocketmine\nbt\TreeRoot;
|
use pocketmine\nbt\TreeRoot;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use function base64_decode;
|
use function base64_decode;
|
||||||
use function base64_encode;
|
use function base64_encode;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
@ -163,7 +164,7 @@ class Item implements \JsonSerializable{
|
|||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setCustomName(string $name) : Item{
|
public function setCustomName(string $name) : Item{
|
||||||
//TODO: encoding might need to be checked here
|
Utils::checkUTF8($name);
|
||||||
$this->customName = $name;
|
$this->customName = $name;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -193,6 +194,7 @@ class Item implements \JsonSerializable{
|
|||||||
if(!is_string($line)){
|
if(!is_string($line)){
|
||||||
throw new \TypeError("Expected string[], but found " . gettype($line) . " in given array");
|
throw new \TypeError("Expected string[], but found " . gettype($line) . " in given array");
|
||||||
}
|
}
|
||||||
|
Utils::checkUTF8($line);
|
||||||
}
|
}
|
||||||
$this->lore = $lines;
|
$this->lore = $lines;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\item;
|
namespace pocketmine\item;
|
||||||
|
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
|
|
||||||
class WritableBookPage{
|
class WritableBookPage{
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
@ -31,7 +33,8 @@ class WritableBookPage{
|
|||||||
private $photoName;
|
private $photoName;
|
||||||
|
|
||||||
public function __construct(string $text, string $photoName = ""){
|
public function __construct(string $text, string $photoName = ""){
|
||||||
//TODO: data validation, encoding checks
|
//TODO: data validation
|
||||||
|
Utils::checkUTF8($text);
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
$this->photoName = $photoName;
|
$this->photoName = $photoName;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\item;
|
namespace pocketmine\item;
|
||||||
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
|
|
||||||
class WrittenBook extends WritableBookBase{
|
class WrittenBook extends WritableBookBase{
|
||||||
|
|
||||||
@ -92,6 +93,7 @@ class WrittenBook extends WritableBookBase{
|
|||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setAuthor(string $authorName) : self{
|
public function setAuthor(string $authorName) : self{
|
||||||
|
Utils::checkUTF8($authorName);
|
||||||
$this->author = $authorName;
|
$this->author = $authorName;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -113,6 +115,7 @@ class WrittenBook extends WritableBookBase{
|
|||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setTitle(string $title) : self{
|
public function setTitle(string $title) : self{
|
||||||
|
Utils::checkUTF8($title);
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ use function is_readable;
|
|||||||
use function is_string;
|
use function is_string;
|
||||||
use function json_decode;
|
use function json_decode;
|
||||||
use function json_last_error_msg;
|
use function json_last_error_msg;
|
||||||
|
use function mb_check_encoding;
|
||||||
use function ob_end_clean;
|
use function ob_end_clean;
|
||||||
use function ob_get_contents;
|
use function ob_get_contents;
|
||||||
use function ob_start;
|
use function ob_start;
|
||||||
@ -559,4 +560,10 @@ class Utils{
|
|||||||
unlink($dir);
|
unlink($dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function checkUTF8(string $string) : void{
|
||||||
|
if(!mb_check_encoding($string, 'UTF-8')){
|
||||||
|
throw new \InvalidArgumentException("Text must be valid UTF-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user