Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify App::url() code, convert string page to array early #2108

Merged
merged 10 commits into from
Sep 15, 2023
Next Next commit
fix URL for non properly configured $_SERVER
mvorisek committed Sep 15, 2023
commit 342bfb4ae3d21bbc5aac699bc7e209fcd9a97295
9 changes: 5 additions & 4 deletions src/App.php
Original file line number Diff line number Diff line change
@@ -670,16 +670,17 @@ public function url($page = [], array $extraRequestUrlArgs = []): string
} else {
// use current page by default
$requestUrl = $request->getUri()->getPath();
if (substr($requestUrl, -1, 1) === '/') {
if ($requestUrl === '') { // TODO path must always start with '/'
$requestUrl = '/';
}
if (substr($requestUrl, -1) === '/') {
$pagePath = $this->urlBuildingIndexPage;
} else {
$pagePath = basename($requestUrl, $this->urlBuildingExt);
}
}
unset($page[0]);
if ($pagePath) {
$pagePath .= $this->urlBuildingExt;
}
$pagePath .= $this->urlBuildingExt;
}

$args = $extraRequestUrlArgs;
4 changes: 2 additions & 2 deletions tests/CallbackTest.php
Original file line number Diff line number Diff line change
@@ -89,8 +89,8 @@ public function testViewUrlCallback(): void
$this->simulateCallbackTriggering($cbApp);
$this->simulateCallbackTriggering($cb);

$expectedUrlCbApp = '?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'aa=callback&' . Callback::URL_QUERY_TARGET . '=aa';
$expectedUrlCb = '?' . /* Callback::URL_QUERY_TRIGGER_PREFIX . 'aa=1&' . */ Callback::URL_QUERY_TRIGGER_PREFIX . 'bb=callback&' . Callback::URL_QUERY_TARGET . '=bb';
$expectedUrlCbApp = 'index.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'aa=callback&' . Callback::URL_QUERY_TARGET . '=aa';
$expectedUrlCb = 'index.php?' . /* Callback::URL_QUERY_TRIGGER_PREFIX . 'aa=1&' . */ Callback::URL_QUERY_TRIGGER_PREFIX . 'bb=callback&' . Callback::URL_QUERY_TARGET . '=bb';
self::assertSame($expectedUrlCbApp, $cbApp->getUrl());
self::assertSame($expectedUrlCb, $cb->getUrl());