Merge pull request #326 from saraf/master

Handle leading whitespace in JSON body
This commit is contained in:
Maurits van der Schee 2018-01-12 19:28:45 +01:00 • committed by GitHub
commit 7847a66dce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View file

@ -1679,6 +1679,7 @@ class PHP_CRUD_API {
}
protected function retrieveInputs($data) {
$data = trim($data, " \t\n\r");
if (strlen($data)==0) {
$input = false;
} else if ($data[0]=='{' || $data[0]=='[') {

View file

@ -643,4 +643,14 @@ abstract class Tests extends TestBase
$test->get('/posts/1');
$test->expect('{"id":1,"user_id":1,"category_id":1,"content":"blog start\'d"}');
}
public function testAddPostWithLeadingWhitespaceInJSON()
{
$test = new Api($this);
$test->post('/posts', '
{"user_id":1,"category_id":1,"content":"test whitespace"} ');
$test->expect('21');
$test->get('/posts/21');
$test->expect('{"id":21,"user_id":1,"category_id":1,"content":"test whitespace"}');
}
}