Skip to content

Commit

Permalink
Merge pull request #16520 from sinbadxiii/issue-16519
Browse files Browse the repository at this point in the history
fixed skipping application/x-www-form-urlencoded in getPut()
  • Loading branch information
niden authored Jan 29, 2024
2 parents 96d18ec + d402874 commit d968fc9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion phalcon/Http/Request.zep
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,9 @@ class Request extends AbstractInjectionAware implements RequestInterface, Reques
if null === cached {
let contentType = this->getContentType();

if typeof contentType == "string" {
if typeof contentType == "string" &&
(stripos(contentType, "json") != false ||
stripos(contentType, "multipart/form-data") !== false) {

if (stripos(contentType, "json") != false) {
let cached = this->getJsonRawBody(true);
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/Http/Request/GetPutCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,49 @@ public function httpRequestGetPutMultipartFormData(UnitTester $I)

$_SERVER = $store;
}

/**
* Tests Phalcon\Http\Request :: getPut() - x-www-form-urlencoded
*
* @issue @16519
* @author Phalcon Team <[email protected]>
* @since 2024-01-29
*/
public function httpRequestGetPutApplicationtXWwwFormUrlencoded(UnitTester $I)
{
$I->wantToTest('Http\Request - getPut() - x-www-form-urlencoded');

stream_wrapper_unregister('php');
stream_wrapper_register('php', PhpStream::class);

file_put_contents('php://input', 'fruit=orange&quantity=4');

$store = $_SERVER ?? [];
$time = $_SERVER['REQUEST_TIME_FLOAT'];
$_SERVER = [
'REQUEST_TIME_FLOAT' => $time,
'REQUEST_METHOD' => 'PUT',
'CONTENT_TYPE' => "application/x-www-form-urlencoded",
];

$request = new Request();

$expected = [
'fruit' => 'orange',
'quantity' => '4',
];

$actual = file_get_contents('php://input');

$I->assertSame("fruit=orange&quantity=4", $actual);

$I->assertSame(
$expected,
$request->getPut()
);

stream_wrapper_restore('php');

$_SERVER = $store;
}
}

0 comments on commit d968fc9

Please sign in to comment.