Skip to content

Commit 7af5eb3

Browse files
committed
crafting: validate array inputs
this makes sure wrong parameters don't show up as core errors, as seen in crash report 12373907 closes #6642
1 parent aad2bce commit 7af5eb3

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/crafting/ShapedRecipe.php

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function __construct(array $shape, array $ingredients, array $results){
9797

9898
$this->shape = $shape;
9999

100+
Utils::validateArrayValueType($ingredients, function(RecipeIngredient $_) : void{});
100101
foreach(Utils::stringifyKeys($ingredients) as $char => $i){
101102
if(!str_contains(implode($this->shape), $char)){
102103
throw new \InvalidArgumentException("Symbol '$char' does not appear in the recipe shape");
@@ -105,6 +106,7 @@ public function __construct(array $shape, array $ingredients, array $results){
105106
$this->ingredientList[$char] = clone $i;
106107
}
107108

109+
Utils::validateArrayValueType($results, function(Item $_) : void{});
108110
$this->results = Utils::cloneObjectArray($results);
109111
}
110112

src/crafting/ShapelessRecipe.php

+2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function __construct(array $ingredients, array $results, ShapelessRecipeT
5353
if(count($ingredients) > 9){
5454
throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients");
5555
}
56+
Utils::validateArrayValueType($ingredients, function(RecipeIngredient $_) : void{});
5657
$this->ingredients = $ingredients;
58+
Utils::validateArrayValueType($results, function(Item $_) : void{});
5759
$this->results = Utils::cloneObjectArray($results);
5860
}
5961

0 commit comments

Comments
 (0)