add some UTF-8 validation

This commit is contained in:
Dylan K. Taylor
2019-08-01 19:51:31 +01:00
parent 399ef13069
commit 135a2f520c
5 changed files with 19 additions and 5 deletions

View File

@@ -45,6 +45,7 @@ use pocketmine\nbt\tag\StringTag;
use pocketmine\nbt\TreeRoot;
use pocketmine\player\Player;
use pocketmine\utils\Binary;
use pocketmine\utils\Utils;
use function base64_decode;
use function base64_encode;
use function get_class;
@@ -163,7 +164,7 @@ class Item implements \JsonSerializable{
* @return $this
*/
public function setCustomName(string $name) : Item{
//TODO: encoding might need to be checked here
Utils::checkUTF8($name);
$this->customName = $name;
return $this;
}
@@ -193,6 +194,7 @@ class Item implements \JsonSerializable{
if(!is_string($line)){
throw new \TypeError("Expected string[], but found " . gettype($line) . " in given array");
}
Utils::checkUTF8($line);
}
$this->lore = $lines;
return $this;

View File

@@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\utils\Utils;
class WritableBookPage{
/** @var string */
@@ -31,7 +33,8 @@ class WritableBookPage{
private $photoName;
public function __construct(string $text, string $photoName = ""){
//TODO: data validation, encoding checks
//TODO: data validation
Utils::checkUTF8($text);
$this->text = $text;
$this->photoName = $photoName;
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\utils\Utils;
class WrittenBook extends WritableBookBase{
@@ -92,6 +93,7 @@ class WrittenBook extends WritableBookBase{
* @return $this
*/
public function setAuthor(string $authorName) : self{
Utils::checkUTF8($authorName);
$this->author = $authorName;
return $this;
}
@@ -113,6 +115,7 @@ class WrittenBook extends WritableBookBase{
* @return $this
*/
public function setTitle(string $title) : self{
Utils::checkUTF8($title);
$this->title = $title;
return $this;
}