Merge pull request #326 from saraf/master
Handle leading whitespace in JSON body
This commit is contained in:
commit
7847a66dce
2 changed files with 11 additions and 0 deletions
1
api.php
1
api.php
|
|
@ -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]=='[') {
|
||||
|
|
|
|||
|
|
@ -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"}');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue