From d231f1e0003675e2484dc8122feadb30431571f1 Mon Sep 17 00:00:00 2001 From: sanja <52755494+sanjacornelius@users.noreply.github.com> Date: Mon, 1 Jun 2026 13:59:45 -0700 Subject: [PATCH] Add getRequestArray helper to ScriptController Replace repeated json_decode(...) ?: [] usage with a private getRequestArray method. This centralizes request parsing for 'data' and 'config' in preview and the script execution flow, allowing the controller to accept either arrays or JSON strings and default safely to an empty array, reducing duplication and improving robustness. --- .../Http/Controllers/Api/ScriptController.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ProcessMaker/Http/Controllers/Api/ScriptController.php b/ProcessMaker/Http/Controllers/Api/ScriptController.php index 2e7fc5c5dc..be194291ee 100644 --- a/ProcessMaker/Http/Controllers/Api/ScriptController.php +++ b/ProcessMaker/Http/Controllers/Api/ScriptController.php @@ -187,8 +187,8 @@ public function index(Request $request) */ public function preview(Request $request, Script $script) { - $data = json_decode($request->get('data'), true) ?: []; - $config = json_decode($request->get('config'), true) ?: []; + $data = $this->getRequestArray($request->get('data')); + $config = $this->getRequestArray($request->get('config')); $code = $request->get('code'); $nonce = $request->get('nonce'); @@ -245,8 +245,8 @@ public function execute(Request $request, ...$scriptKey) $processRequest = ProcessRequestToken::findOrFail($request->task_id)->processRequest; $script = $script->versionFor($processRequest); } - $data = json_decode($request->get('data'), true) ?: []; - $config = json_decode($request->get('config'), true) ?: []; + $data = $this->getRequestArray($request->get('data')); + $config = $this->getRequestArray($request->get('config')); $watcher = $request->get('watcher', uniqid('scr', true)); $code = $script->code; @@ -561,4 +561,17 @@ public function close(Script $script) return response([], 204); } + + private function getRequestArray($value): array + { + if (is_array($value)) { + return $value; + } + + if (is_string($value)) { + return json_decode($value, true) ?: []; + } + + return []; + } }