Skip to content

Commit c9746f9

Browse files
committed
[#16752] - Merge branch '5.0.x' into T16752-create-docker-image-on-release
2 parents 9c3c4a4 + 69d3524 commit c9746f9

File tree

4 files changed

+74
-10
lines changed

4 files changed

+74
-10
lines changed

Diff for: CHANGELOG-5.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Fixed `Phalcon\Mvc\Router` to correctly handle numeric URI parts as it was in v3 [#16741](https://github.com/phalcon/cphalcon/issues/16741)
1515
- Fixed `Phalcon\Mvc\Model\Binder` to use ReflectionParameter::getType() instead of deprecated method, PHP 8.0 or higher issue. [#16742](https://github.com/phalcon/cphalcon/issues/16742)
1616
- Fixed `Phalcon\Mvc\Model\Query` to check if cache entry exists. [#16747](https://github.com/phalcon/cphalcon/issues/16747)
17+
- Fixed `Phalcon\Mvc\Router` to correctly match route when using query string URIs. [#16749](https://github.com/phalcon/cphalcon/issues/16749)
1718

1819
### Removed
1920

Diff for: phalcon/Mvc/Router.zep

+18-10
Original file line numberDiff line numberDiff line change
@@ -613,33 +613,41 @@ class Router extends AbstractInjectionAware implements RouterInterface, EventsAw
613613
*/
614614
public function getRewriteUri() -> string
615615
{
616-
var url, urlParts, realUri;
616+
var url;
617617

618618
/**
619619
* By default we use $_GET["url"] to obtain the rewrite information
620620
*/
621621
if (self::URI_SOURCE_GET_URL === this->uriSource) {
622622
if fetch url, _GET["_url"] {
623623
if !empty url {
624-
return url;
624+
return this->extractRealUri(url);
625625
}
626626
}
627627
} else {
628628
/**
629629
* Otherwise use the standard $_SERVER["REQUEST_URI"]
630630
*/
631631
if fetch url, _SERVER["REQUEST_URI"] {
632-
let urlParts = explode("?", url),
633-
realUri = urlParts[0];
634-
if !empty realUri {
635-
return realUri;
636-
}
632+
if !empty url {
633+
return this->extractRealUri(url);
634+
}
637635
}
638636
}
639637

640638
return "/";
641639
}
642640

641+
protected function extractRealUri(string! uri) -> string
642+
{
643+
var urlParts, realUri;
644+
645+
let urlParts = explode("?", uri, 2),
646+
realUri = urlParts[0];
647+
648+
return realUri;
649+
}
650+
643651
/**
644652
* Returns a route object by its id
645653
*
@@ -727,13 +735,13 @@ class Router extends AbstractInjectionAware implements RouterInterface, EventsAw
727735
paramsStr, part, parts, paths, pattern, position, realUri,
728736
regexHostName, request, route, routeFound, strParams, vnamespace;
729737

730-
let realUri = uri;
731-
732-
if !realUri {
738+
if !uri {
733739
/**
734740
* If 'uri' isn't passed as parameter it reads _GET["_url"]
735741
*/
736742
let realUri = this->getRewriteUri();
743+
} else {
744+
let realUri = this->extractRealUri(uri);
737745
}
738746

739747
/**

Diff for: tests/_data/fixtures/Mvc/Router.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Phalcon\Tests\Fixtures\Mvc;
4+
5+
class Router extends \Phalcon\Mvc\Router
6+
{
7+
public function protectedExtractRealUri($uri)
8+
{
9+
return parent::extractRealUri($uri);
10+
}
11+
}

Diff for: tests/integration/Mvc/Router/ExtractRealUriCest.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon Framework.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Tests\Integration\Mvc\Router;
15+
16+
use IntegrationTester;
17+
use Phalcon\Di\FactoryDefault;
18+
use Phalcon\Tests\Fixtures\Mvc\Router;
19+
20+
class ExtractRealUriCest
21+
{
22+
/**
23+
* Tests Phalcon\Mvc\Router :: extractRealUri()
24+
*
25+
* @author Phalcon Team <[email protected]>
26+
* @since 2025-04-11
27+
* @issue 16749
28+
*/
29+
public function testExtractRealUri(IntegrationTester $I): void
30+
{
31+
$router = new Router(false);
32+
$router->setDI(new FactoryDefault());
33+
34+
$realUri = $router->protectedExtractRealUri(
35+
'/admin/private/businesses/list/my/123?query=string'
36+
);
37+
$I->assertSame('/admin/private/businesses/list/my/123', $realUri);
38+
39+
$realUri = $router->protectedExtractRealUri(
40+
'/admin/private/businesses/list/my/123'
41+
);
42+
$I->assertSame('/admin/private/businesses/list/my/123', $realUri);
43+
}
44+
}

0 commit comments

Comments
 (0)