From acc1c5a352b970fa7515680de1cfc34d73f4b18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20G=2E=20J=C3=B8rgensen?= Date: Fri, 28 May 2021 16:06:41 +0200 Subject: [PATCH] Better checks to ensure values are the correct type --- src/MinecraftJSONColors.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MinecraftJSONColors.php b/src/MinecraftJSONColors.php index b4eabf1..b28f191 100644 --- a/src/MinecraftJSONColors.php +++ b/src/MinecraftJSONColors.php @@ -79,7 +79,7 @@ public static function convertToLegacy($json, string $color_char = '§', bool $h self::$color_char = $color_char; self::$hex_colors = $hex_colors; - if (is_string($json)) { + if (!empty($json) && is_string($json)) { $json = json_decode($json, true); //Just return an empty string, if JSON was invalid. @@ -101,7 +101,8 @@ public static function convertToLegacy($json, string $color_char = '§', bool $h } } - $legacy .= self::parseElement($json); + if (is_array($json)) + $legacy .= self::parseElement($json); //If nothing was parsed until here, it's an array of components. if (empty($legacy) && is_array($json)) {