Skip to content

Commit 2c01bea

Browse files
committed
Added extra protection to the encoding/decoding of JSON data
1 parent de56bdc commit 2c01bea

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

classes/db/DAO.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public function convertFromDB($value, $type, $nullable = false)
333333
$decodedValue = json_decode($value ?? ($type === 'array' ? '[]' : '{}'), true);
334334
// FIXME: pkp/pkp-lib#6250 Remove after 3.3.x upgrade code is removed (see also pkp/pkp-lib#5772)
335335
if (!is_null($decodedValue)) {
336-
return $decodedValue;
336+
return $type === 'array' ? array_values((array) $decodedValue) : (object) $decodedValue;
337337
} else {
338338
return unserialize($value);
339339
}
@@ -399,6 +399,9 @@ public function convertToDB($value, &$type, $nullable = false)
399399
switch ($type) {
400400
case 'object':
401401
case 'array':
402+
if ($value !== null) {
403+
$value = $type === 'array' ? array_values((array) $value) : (object) $value;
404+
}
402405
$value = json_encode($value, JSON_UNESCAPED_UNICODE);
403406
break;
404407
case 'bool':

0 commit comments

Comments
 (0)