Skip to content

Commit

Permalink
fix JsonResponse::fromJasonString() double encoding string
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Lieffring committed Apr 21, 2021
1 parent fd0864a commit f356e1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Illuminate/Http/JsonResponse.php
Expand Up @@ -22,13 +22,14 @@ class JsonResponse extends BaseJsonResponse
* @param int $status
* @param array $headers
* @param int $options
* @param bool $json
* @return void
*/
public function __construct($data = null, $status = 200, $headers = [], $options = 0)
public function __construct($data = null, $status = 200, $headers = [], $options = 0, $json = false)
{
$this->encodingOptions = $options;

parent::__construct($data, $status, $headers);
parent::__construct($data, $status, $headers, $json);
}

/**
Expand Down Expand Up @@ -118,4 +119,12 @@ public function hasEncodingOption($option)
{
return (bool) ($this->encodingOptions & $option);
}

/**
* {@inheritdoc}
*/
public static function fromJsonString(?string $data = null, int $status = 200, array $headers = [])
{
return new static($data, $status, $headers, 0, true);
}
}
8 changes: 8 additions & 0 deletions tests/Http/HttpJsonResponseTest.php
Expand Up @@ -104,6 +104,14 @@ public function jsonErrorDataProvider()
[$nan],
];
}

public function testFromJsonString()
{
$json_string = '{"foo":"bar"}';
$response = JsonResponse::fromJsonString($json_string);

$this->assertSame('bar', $response->getData()->foo);
}
}

class JsonResponseTestJsonableObject implements Jsonable
Expand Down

0 comments on commit f356e1b

Please sign in to comment.