Skip to content

Commit 9104f8e

Browse files
committed
Fix JSON error when comment has no reactions
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 9c42717 commit 9104f8e

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lib/private/Comments/Manager.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,22 @@ protected function normalizeDatabaseData(array $data) {
110110
$data['children_count'] = (int)$data['children_count'];
111111
$data['reference_id'] = $data['reference_id'] ?? null;
112112
if ($this->supportReactions()) {
113-
$list = json_decode($data['reactions'], true);
114-
// Ordering does not work on the database with group concat and Oracle,
115-
// So we simply sort on the output.
116-
if (is_array($list)) {
117-
uasort($list, static function ($a, $b) {
118-
if ($a === $b) {
119-
return 0;
120-
}
121-
return ($a > $b) ? -1 : 1;
122-
});
113+
if ($data['reactions']) {
114+
$list = json_decode($data['reactions'], true);
115+
// Ordering does not work on the database with group concat and Oracle,
116+
// So we simply sort on the output.
117+
if (is_array($list)) {
118+
uasort($list, static function ($a, $b) {
119+
if ($a === $b) {
120+
return 0;
121+
}
122+
return ($a > $b) ? -1 : 1;
123+
});
124+
}
125+
$data['reactions'] = $list;
126+
} else {
127+
$data['reactions'] = [];
123128
}
124-
$data['reactions'] = $list;
125129
}
126130
return $data;
127131
}

0 commit comments

Comments
 (0)