mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Coerce only single model rules, never unions
Coercing a union-typed value into a Document reached a branch that had never run: the single-value path hands rule['type'] to output(), which takes a string, so a user's hashOptions returned a 500 instead of its algo. Only the array branch resolves a model per item. Restrict the coercion to array rules naming one model, and leave the single-value path as it was.
This commit is contained in:
1 parent
19dff5c974
commit
c52584df17
1 file changed
+2
-5
@@ -563,7 +563,8 @@ class Response extends SwooleResponse
|
||||
|
||||
foreach ($data[$key] as $index => $item) {
|
||||
// A model-typed rule handed a raw array would otherwise ship every key it carries.
|
||||
if (\is_array($item) && (\is_array($rule['type']) || self::hasModel($rule['type']))) {
|
||||
// Union types are left alone: their branch resolves a model per item.
|
||||
if (\is_array($item) && !\is_array($rule['type']) && self::hasModel($rule['type'])) {
|
||||
$item = new Document($item);
|
||||
}
|
||||
|
||||
@@ -602,10 +603,6 @@ class Response extends SwooleResponse
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (\is_array($data[$key]) && (\is_array($rule['type']) || self::hasModel($rule['type']))) {
|
||||
$data[$key] = new Document($data[$key]);
|
||||
}
|
||||
|
||||
if ($data[$key] instanceof Document) {
|
||||
$data[$key] = $this->output($data[$key], $rule['type']);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user