Skip to content

Commit 7847a66

Browse files
authored
Merge pull request #326 from saraf/master
Handle leading whitespace in JSON body
2 parents 9bbc5bb + b746794 commit 7847a66

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

api.php

+1
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ protected function findRelations($tables,$database,$auto_include) {
16791679
}
16801680

16811681
protected function retrieveInputs($data) {
1682+
$data = trim($data, " \t\n\r");
16821683
if (strlen($data)==0) {
16831684
$input = false;
16841685
} else if ($data[0]=='{' || $data[0]=='[') {

tests/Tests.php

+10
Original file line numberDiff line numberDiff line change
@@ -643,4 +643,14 @@ public function testEditPostWithApostrophe()
643643
$test->get('/posts/1');
644644
$test->expect('{"id":1,"user_id":1,"category_id":1,"content":"blog start\'d"}');
645645
}
646+
647+
public function testAddPostWithLeadingWhitespaceInJSON()
648+
{
649+
$test = new Api($this);
650+
$test->post('/posts', '
651+
{"user_id":1,"category_id":1,"content":"test whitespace"} ');
652+
$test->expect('21');
653+
$test->get('/posts/21');
654+
$test->expect('{"id":21,"user_id":1,"category_id":1,"content":"test whitespace"}');
655+
}
646656
}

0 commit comments

Comments
 (0)