Skip to content

Commit

Permalink
fix: Bug on Adding Query String
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Dec 1, 2024
1 parent a8ab501 commit 0234fdb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tests/webfiori/tests/http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ public function testGetRequestedURL01() {
$this->assertEquals('http://127.0.0.1/my/app?param1=something&param2=something_else', Request::getRequestedURI());
$_GET = [];
}
/**
* @test
*/
public function testGetRequestedURL03() {
putenv('REQUEST_URI=/my/app/x');
$this->assertEquals('http://127.0.0.1/my/app/x', Request::getRequestedURI());
}
/**
* @test
*/
public function testGetRequestedURL04() {
putenv('REQUEST_URI=/my/app/x?b=p');
$_GET['c'] = 'k';
$this->assertEquals('http://127.0.0.1/my/app/x?c=k', Request::getRequestedURI());
$_GET = [];
}
/**
* @test
*/
Expand Down
8 changes: 7 additions & 1 deletion webfiori/http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,17 @@ public static function getRequestedURI(string $pathToAppend = '') : string {
// Using built-in server, it will be false
$path = $_SERVER['PATH_INFO'] ?? '';
}


if (strpos($path, '?') !== false) {
$split = explode('?', $path);
$path = $split[0];
}

$cleanedPath = str_replace(trim(str_replace('\\', '/', $pathToAppend), '/'),'' ,trim(filter_var($path),'/'));
$requestMethod = self::getMethod();
$queryString = '';


if ($requestMethod == RequestMethod::DELETE || $requestMethod == RequestMethod::GET) {
$getParams = Request::getParams();

Expand Down

0 comments on commit 0234fdb

Please sign in to comment.