diff --git a/phalcon/Http/Request.zep b/phalcon/Http/Request.zep index be9ed7e50b..97fb800a67 100644 --- a/phalcon/Http/Request.zep +++ b/phalcon/Http/Request.zep @@ -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); diff --git a/tests/unit/Http/Request/GetPutCest.php b/tests/unit/Http/Request/GetPutCest.php index 41a174466f..e6a6607fd3 100644 --- a/tests/unit/Http/Request/GetPutCest.php +++ b/tests/unit/Http/Request/GetPutCest.php @@ -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 + * @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; + } }