From e5f0ca77a92733fee710a9414fec33d0ee07cd9e Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 23 Jun 2022 12:55:03 +0300 Subject: [PATCH] fix request wrapper --- application/Espo/Core/Api/RequestWrapper.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/application/Espo/Core/Api/RequestWrapper.php b/application/Espo/Core/Api/RequestWrapper.php index 2997c3bc38..9952bccbe7 100644 --- a/application/Espo/Core/Api/RequestWrapper.php +++ b/application/Espo/Core/Api/RequestWrapper.php @@ -202,14 +202,20 @@ class RequestWrapper implements ApiRequest $contents = $this->getBodyContents(); if ($this->getContentType() === 'application/json' && $contents) { - $this->parsedBody = Json::decode($contents); + $parsedBody = Json::decode($contents); - if (is_array($this->parsedBody)) { - $this->parsedBody = (object) [ - 'list' => $this->parsedBody, + if (is_array($parsedBody)) { + $parsedBody = (object) [ + 'list' => $parsedBody, ]; } + if (!$parsedBody instanceof stdClass) { + throw new Error("Body is not a JSON object."); + } + + $this->parsedBody = $parsedBody; + return; }