Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve request parsing with invalid json #2066

Merged
merged 1 commit into from Mar 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/Http/RequestTest.php
Expand Up @@ -751,6 +751,36 @@ public function testGetParsedBodyJson()
$this->assertEquals(['foo' => 'bar'], $request->getParsedBody());
}

public function testGetParsedBodyInvalidJson()
{
$method = 'GET';
$uri = new Uri('https', 'example.com', 443, '/foo/bar', 'abc=123', '', '');
$headers = new Headers();
$headers->set('Content-Type', 'application/json;charset=utf8');
$cookies = [];
$serverParams = [];
$body = new RequestBody();
$body->write('{foo}bar');
$request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);

$this->assertNull($request->getParsedBody());
}

public function testGetParsedBodySemiValidJson()
{
$method = 'GET';
$uri = new Uri('https', 'example.com', 443, '/foo/bar', 'abc=123', '', '');
$headers = new Headers();
$headers->set('Content-Type', 'application/json;charset=utf8');
$cookies = [];
$serverParams = [];
$body = new RequestBody();
$body->write('"foo bar"');
$request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);

$this->assertNull($request->getParsedBody());
}

public function testGetParsedBodyWithJsonStructuredSuffix()
{
$method = 'GET';
Expand Down