Skip to content

Commit

Permalink
Parse POST data even if multipart/form-data request
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Lockhart committed Apr 19, 2012
1 parent dd4caa8 commit ea6e77f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ public function post( $key = null ) {
parse_str($this->env['slim.input'], $output);
}
$this->env['slim.request.form_hash'] = Slim_Http_Util::stripSlashesIfMagicQuotes($output);
} else {
$this->env['slim.request.form_hash'] = Slim_Http_Util::stripSlashesIfMagicQuotes($_POST);
}
}
if ( $key ) {
Expand Down
17 changes: 17 additions & 0 deletions tests/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,23 @@ public function testPostWithoutInput() {
$req->post('foo');
}

/**
* Test fetch POST params even if multipart/form-data request
*/
public function testPostWithMultipartRequest() {
$_POST = array('foo' => 'bar'); //<-- Set by PHP
$env = Slim_Environment::mock(array(
'REQUEST_METHOD' => 'POST',
'slim.input' => '', //<-- "php://input" is empty for multipart/form-data requests
'CONTENT_TYPE' => 'multipart/form-data',
'CONTENT_LENGTH' => 0
));
$req = new Slim_Http_Request($env);
$this->assertEquals(1, count($req->post()));
$this->assertEquals('bar', $req->post('foo'));
$this->assertNull($req->post('xyz'));
}

/**
* Test fetch PUT params
*/
Expand Down

0 comments on commit ea6e77f

Please sign in to comment.