Skip to content

Commit f4321be

Browse files
committed
JsonNbtParser: fixed TypeError being thrown when mixing ListTag value types
1 parent e24c007 commit f4321be

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/JsonNbtParser.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,15 @@ private static function parseList(BinaryStream $stream) : ListTag{
7878
if(self::skipWhitespace($stream, "]")){
7979
while(!$stream->feof()){
8080
try{
81-
$retval->push(self::readValue($stream));
81+
$value = self::readValue($stream);
8282
}catch(InvalidTagValueException $e){
8383
throw new NbtDataException("Data error: " . $e->getMessage());
8484
}
85+
$expectedType = $retval->getTagType();
86+
if($expectedType !== NBT::TAG_End && $expectedType !== $value->getType()){
87+
throw new NbtDataException("Data error: lists can only contain one type of value");
88+
}
89+
$retval->push($value);
8590
if(self::readBreak($stream, "]")){
8691
return $retval;
8792
}

tests/phpunit/JsonNbtParserTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testEmptyList() : void{
6969
}
7070

7171
public function testMixedList() : void{
72-
$this->expectException(\TypeError::class); //TODO: throwing an engine level error on userdata is very bad ...
72+
$this->expectExceptionMessage("lists can only contain one type of value");
7373
JsonNbtParser::parseJson("{TestList:[1f, string2, 3b]}");
7474
}
7575

0 commit comments

Comments
 (0)