1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-01-27 23:18:19 +01:00

JSON rendering: Avoid exception iterating on non-iterable objects

Summary:
Check for `is_iterable($object)` (available since PHP 7.1) to avoid an exception calling `foreach` on `$object` in the rare case that the object is a custom Phorge class (`PHUIBoxView`, `PhutilSafeHTML`) and not an array. cf https://we.phorge.it/rARC7570dd0da119627ff83bc6db3be06b51eb5b366b for a similar patch to handle PHP stdClass objects.

See downstream https://phabricator.wikimedia.org/T373316.

Test Plan:
* Unclear to reproduce the actual issue, likely something Feed related.
* Open an existing JSON Paste at http://phorge.localhost/P1 and see that it still renders.
* Open an existing JSON File at http://phorge.localhost/F1 and see that it still renders.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Differential Revision: https://we.phorge.it/D25855
This commit is contained in:
Andre Klapper 2025-01-10 11:51:08 +01:00
parent abda702083
commit f0176263a7

View file

@ -51,7 +51,7 @@ final class PhutilJSON extends Phobject {
$object = (array)$object;
}
if (empty($object)) {
if (empty($object) || !is_iterable($object)) {
return '{}';
}