Skip to content

Commit 26dc6fb

Browse files
committed
FIX: Strip trailing slash from virtual URI if it matches a real URI (ex: for sub-applications that have their own index.php on a subfolder).
FIX: on Windows, loading templates whose paths do not have extensions failed.
1 parent ad032f6 commit 26dc6fb

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

subsystems/view-engine/ViewEngine/Services/ViewService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function resolveTemplatePath ($path, &$base = null, &$viewPath = null)
191191
// The path was not a direct path to the file; we must now search for the template on all registered directories.
192192
$dirs = $this->engineSettings->getDirectories ();
193193
foreach ($dirs as $base) {
194-
$p = "$base/$path";
194+
$p = normalizePath ("$base/$path");
195195
if ($p = $this->findTemplate ($p)) {
196196
$viewPath = $path;
197197
return $p;

subsystems/web-server/WebServer/WebServer.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,23 @@ function run ()
7272
function setup ()
7373
{
7474
/** @var ServerRequestInterface $request */
75-
$request = ServerRequest::fromGlobals ();
76-
$uri = $request->getUri ();
77-
$basePath = dirnameEx ($request->getServerParams () ['SCRIPT_NAME'], $this->kernelSettings->urlDepth + 1);
78-
$scheme = $uri->getScheme () ?: 'http';
79-
$port = $uri->getPort ();
80-
$baseUrl = sprintf ('%s://%s%s%s', $scheme, $uri->getHost (),
75+
$request = ServerRequest::fromGlobals ();
76+
$uri = $request->getUri ();
77+
$scriptName = $request->getServerParams () ['SCRIPT_NAME'];
78+
$realBasePath = dirname ($scriptName);
79+
$basePath = dirnameEx ($scriptName, $this->kernelSettings->urlDepth + 1);
80+
$scheme = $uri->getScheme () ?: 'http';
81+
$port = $uri->getPort ();
82+
$baseUrl = sprintf ('%s://%s%s%s', $scheme, $uri->getHost (),
8183
$port ? ($port == 80 && $scheme == 'http' || $port == 443 && $scheme == 'https' ? '' : ":$port") : '',
8284
$basePath);
83-
$virtualUri = ltrim (substr ($uri->getPath (), strlen ($basePath)), '/');
84-
$query = $uri->getQuery ();
85+
$path = $uri->getPath ();
86+
$virtualUri = ltrim (substr ($path, strlen ($basePath)), '/');
87+
$realVirtualUri = substr ($path, strlen ($realBasePath));
88+
// Strip trailing slash from virtual URI if it matches a real URI (ex: for sub-applications that have their own index.php on a subfolder)
89+
if (substr ($realVirtualUri, -1) == '/')
90+
$virtualUri = rtrim ($virtualUri, '/');
91+
$query = $uri->getQuery ();
8592

8693
$this->kernelSettings->baseUrl = $baseUrl;
8794
$this->kernelSettings->basePath = $basePath;

0 commit comments

Comments
 (0)