Skip to content

Commit

Permalink
Merge pull request #60 from WebFiori/fix-get-uri
Browse files Browse the repository at this point in the history
fix: Add Missing Query String to URI
  • Loading branch information
usernane authored Nov 20, 2024
2 parents 00d1afe + 4db2020 commit 2a78061
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/php83.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,26 @@ jobs:
- name: CodeCov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
release_staging:
needs:
- "test"
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev'
steps:
- uses: actions/checkout@v4
- uses: google-github-actions/release-please-action@v3
with:
release-type: php
token: ${{ secrets.GITHUB_TOKEN }}
release_prod:
needs:
- "test"
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- uses: google-github-actions/release-please-action@v3
with:
release-type: php
token: ${{ secrets.GITHUB_TOKEN }}
14 changes: 14 additions & 0 deletions tests/webfiori/tests/http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testGetParam02() {
putenv('REQUEST_METHOD=GET');
$_GET['ok'] = 'I not Ok';
$this->assertEquals('I not Ok', Request::getParam('ok'));
$_GET = [];
}
/**
* @test
Expand All @@ -53,6 +54,7 @@ public function testGetParam05() {
putenv('REQUEST_METHOD=GET');
$_GET['hello'] = 'This%20is%20an%20encoded%20string.';
$this->assertEquals('This is an encoded string.', Request::getParam('hello'));
$_GET = [];
}
/**
* @test
Expand All @@ -61,6 +63,7 @@ public function testGetParam06() {
putenv('REQUEST_METHOD=GET');
$_GET['hello'] = 'This+is+an+encoded%20string.';
$this->assertEquals('This is an encoded string.', Request::getParam('hello'));
$_GET = [];
}
/**
* @test
Expand All @@ -69,6 +72,7 @@ public function testGetParams06() {
putenv('REQUEST_METHOD=GET');
$_GET['arabic'] = '%D9%86%D8%B5%20%D8%B9%D8%B1%D8%A8%D9%8A';
$this->assertEquals('نص عربي', Request::getParam('arabic'));
$_GET = [];
}
/**
* @test
Expand Down Expand Up @@ -104,6 +108,16 @@ public function testGetRequestedURL00() {
$_SERVER['PATH_INFO'] = '/my/app';
$this->assertEquals('http://127.0.0.1/my/app', Request::getRequestedURI());
}
/**
* @test
*/
public function testGetRequestedURL01() {
$_SERVER['PATH_INFO'] = '/my/app';
$_GET['param1'] = 'something';
$_GET['param2'] = 'something_else';
$this->assertEquals('http://127.0.0.1/my/app?param1=something&param2=something_else', Request::getRequestedURI());
$_GET = [];
}
/**
* @test
*/
Expand Down
17 changes: 15 additions & 2 deletions webfiori/http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,21 @@ public static function getRequestedURI(string $pathToAppend = '') : string {
}

$cleanedPath = str_replace(trim(str_replace('\\', '/', $pathToAppend), '/'),'' ,trim(filter_var($path),'/'));

return $base.'/'.trim($cleanedPath, '/');
$requestMethod = self::getMethod();
$queryString = '';

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

if (count($getParams) != 0) {
$queryArr = [];
foreach ($getParams as $name => $val) {
$queryArr[] = $name.'='.$val;
}
$queryString = '?'.implode('&', $queryArr);
}
}
return $base.'/'.trim($cleanedPath, '/').$queryString;
}
/**
* Returns an object that holds all information about requested URI.
Expand Down

0 comments on commit 2a78061

Please sign in to comment.