diff --git a/composer.json b/composer.json index 015fc5891..86d4b0cf6 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "pocketmine/nbt": "^0.2.1", "pocketmine/math": "^0.2.0", "pocketmine/snooze": "^0.1.0", - "daverandom/callback-validator": "dev-master" + "daverandom/callback-validator": "dev-master", + "adhocore/json-comment": "^0.0.7" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 25003db99..ccb0db0dd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,52 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2d120a3dd7d68958809c3662d1cb7c99", + "content-hash": "d3fb809caf4d5a5c99054f47f28ff271", "packages": [ + { + "name": "adhocore/json-comment", + "version": "v0.0.7", + "source": { + "type": "git", + "url": "https://github.com/adhocore/php-json-comment.git", + "reference": "135356c7e7336ef59924f1d921c770045f937a76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/adhocore/php-json-comment/zipball/135356c7e7336ef59924f1d921c770045f937a76", + "reference": "135356c7e7336ef59924f1d921c770045f937a76", + "shasum": "" + }, + "require": { + "php": ">=5.4" + }, + "require-dev": { + "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Ahc\\Json\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jitendra Adhikari", + "email": "jiten.adhikary@gmail.com" + } + ], + "description": "Lightweight JSON comment stripper library for PHP", + "keywords": [ + "comment", + "json", + "strip-comment" + ], + "time": "2018-08-01T12:27:26+00:00" + }, { "name": "daverandom/callback-validator", "version": "dev-master", diff --git a/src/pocketmine/resourcepacks/ZippedResourcePack.php b/src/pocketmine/resourcepacks/ZippedResourcePack.php index 35849d698..c381a36bf 100644 --- a/src/pocketmine/resourcepacks/ZippedResourcePack.php +++ b/src/pocketmine/resourcepacks/ZippedResourcePack.php @@ -25,6 +25,8 @@ declare(strict_types=1); namespace pocketmine\resourcepacks; +use Ahc\Json\Comment as CommentedJsonDecoder; + class ZippedResourcePack implements ResourcePack{ /** @@ -86,10 +88,13 @@ class ZippedResourcePack implements ResourcePack{ $archive->close(); - $manifest = json_decode($manifestData); - if($manifest === null){ - throw new ResourcePackException("Failed to parse manifest.json: " . json_last_error_msg()); + //maybe comments in the json, use stripped decoder (thanks mojang) + try{ + $manifest = (new CommentedJsonDecoder())->decode($manifestData); + }catch(\RuntimeException $e){ + throw new ResourcePackException("Failed to parse manifest.json: " . $e->getMessage(), $e->getCode(), $e); } + if(!self::verifyManifest($manifest)){ throw new ResourcePackException("manifest.json is missing required fields"); }