Skip to content

Commit 7eca5e3

Browse files
authored
Inccorectly formated JSON response , if body is string
JSON was not correctly formatted in case we providing a string to setJSON() method. Of course, this is not the final solution but I am pointing out the place where the issue occurs. ``` $this->response ->setJSON(time().'get') ->send(); ```
1 parent 4a3011b commit 7eca5e3

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

system/HTTP/Response.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,9 @@ public function setContentType(string $mime, string $charset = 'UTF-8')
447447
*
448448
* @return $this
449449
*/
450-
public function setJSON($body)
450+
public function setJSON($body, bool $unencoded = true)
451451
{
452-
$this->body = $this->formatBody($body, 'json');
452+
$this->body = $this->formatBody($body, 'json' . ($unencoded ? '-unencoded' : ''));
453453

454454
return $this;
455455
}
@@ -542,7 +542,7 @@ protected function formatBody($body, string $format)
542542
$this->bodyFormat = $format;
543543

544544
// Nothing much to do for a string...
545-
if (! is_string($body))
545+
if (! is_string($body) || $format === 'json-unencoded')
546546
{
547547
/**
548548
* @var Format $config

0 commit comments

Comments
 (0)