Skip to content

Commit

Permalink
refactor: remove adjustPathTrailingSlash()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 25, 2023
1 parent e6648a9 commit 9751854
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions system/HTTP/SiteURI.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function baseUrl($relativePath = '', ?string $scheme = null): string
return URI::createURIString(
$uri->getScheme(),
$uri->getAuthority(),
$this->adjustPathTrailingSlash($uri, $relativePath),
$uri->getPath(),
$uri->getQuery(),
$uri->getFragment()
);
Expand Down Expand Up @@ -420,30 +420,12 @@ public function siteUrl($relativePath = '', ?string $scheme = null, ?App $config

$uri = new self($config, $relativePath, $host, $scheme);

// Adjust path
$path = $this->adjustPathTrailingSlash($uri, $relativePath);
if ($config->indexPage !== '' && $relativePath === '') {
$path = rtrim($path, '/');
}

return URI::createURIString(
$uri->getScheme(),
$uri->getAuthority(),
$path,
$uri->getPath(),
$uri->getQuery(),
$uri->getFragment()
);
}

private function adjustPathTrailingSlash(self $uri, string $relativePath): string
{
$parts = parse_url($this->getBaseURL() . $relativePath);
$path = $parts['path'] ?? '';

if (substr($path, -1) === '/' && substr($uri->getPath(), -1) !== '/') {
return $uri->getPath() . '/';
}

return $uri->getPath();
}
}

0 comments on commit 9751854

Please sign in to comment.