WritableBookBase: fixed crash when finding pages containing corrupted UTF-8 characters

maybe we should treat this as corrupted? but for now, it's consistent with how we deal with signs.
This commit is contained in:
Dylan K. Taylor 2021-12-10 16:39:13 +00:00
parent 6b40ed7bf8
commit 3b77462935
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -31,6 +31,7 @@ use function array_push;
use function array_slice; use function array_slice;
use function array_values; use function array_values;
use function count; use function count;
use function mb_scrub;
abstract class WritableBookBase extends Item{ abstract class WritableBookBase extends Item{
public const TAG_PAGES = "pages"; //TAG_List<TAG_Compound> public const TAG_PAGES = "pages"; //TAG_List<TAG_Compound>
@ -168,12 +169,12 @@ abstract class WritableBookBase extends Item{
if($pages->getTagType() === NBT::TAG_Compound){ //PE format if($pages->getTagType() === NBT::TAG_Compound){ //PE format
/** @var CompoundTag $page */ /** @var CompoundTag $page */
foreach($pages as $page){ foreach($pages as $page){
$this->pages[] = new WritableBookPage($page->getString(self::TAG_PAGE_TEXT), $page->getString(self::TAG_PAGE_PHOTONAME, "")); $this->pages[] = new WritableBookPage(mb_scrub($page->getString(self::TAG_PAGE_TEXT), 'UTF-8'), $page->getString(self::TAG_PAGE_PHOTONAME, ""));
} }
}elseif($pages->getTagType() === NBT::TAG_String){ //PC format }elseif($pages->getTagType() === NBT::TAG_String){ //PC format
/** @var StringTag $page */ /** @var StringTag $page */
foreach($pages as $page){ foreach($pages as $page){
$this->pages[] = new WritableBookPage($page->getValue()); $this->pages[] = new WritableBookPage(mb_scrub($page->getValue(), 'UTF-8'));
} }
} }
} }