Skip to content

Commit

Permalink
Actually the JSON string should not be converted into an associative …
Browse files Browse the repository at this point in the history
…array because the information is lost whether an empty array was an object without properties or an empty array before the conversion.

If it were done correctly this will break existing code in core and all plugins, so the current implementation which is doing the conversion to an associative array instead an PHP object will be kept for compatibility reasons.

Signed-off-by: Volker Theile <votdev@gmx.de>
  • Loading branch information
votdev committed May 9, 2024
1 parent 690ab16 commit 4dccd08
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions deb/openmediavault/usr/sbin/omv-engined
Original file line number Diff line number Diff line change
Expand Up @@ -517,25 +517,22 @@ while(FALSE === $sigTerm) {
require_once("openmediavault/env.inc");

try {
// Decode JSON string to a PHP object.
if (NULL === ($request = json_decode_safe($request))) {
// Decode JSON string to an associative array.
// !!! Note !!!
// Actually the JSON string should not be converted into an
// associative array because the information is lost whether an
// empty array was an object without properties or an empty array
// before the conversion.
// If it were done correctly this will break existing code in core
// and all plugins, so the current implementation which is doing
// the conversion to an associative array instead an PHP object
// will be kept for compatibility reasons.
if (NULL === ($request = json_decode_safe($request, TRUE))) {
throw new \OMV\Exception(
"Failed to decode JSON string: %s",
json_last_error_msg());
}

// Bring the variable into the expected form.
// Note, `params` shouldn't be converted to an array here,
// but this will break existing code in core and all plugins, so
// the current implementation will be kept for compatibility
// reasons.
$request = [
"service" => $request->service,
"method" => $request->method,
"params" => toArray($request->params),
"context" => toArray($request->context)
];

////////////////////////////////////////////////////////////////
// Execute RPC.
////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 4dccd08

Please sign in to comment.