From 9bed188175b906ebacbf6a5f0f8f94561d5aa59c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 7 May 2020 19:30:37 +0200 Subject: [PATCH] fix uri parsing with fragment --- Uri/UriFactory.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 94bad6a63..8bcc4e0e8 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -192,10 +192,17 @@ final class UriFactory */ private static function unique(string $url) : string { - $parts = \explode('&', \str_replace('?', '&', $url)); - $query = ''; + $parts = \explode('&', \str_replace('?', '&', $url)); + $query = ''; + $partCount = \count($parts); + $fragment = ''; - if (\count($parts) > 1) { + if (($fragStart = \strripos($parts[$partCount - 1], '#')) !== false) { + $fragment = \substr($parts[$partCount - 1], $fragStart); + $parts[$partCount - 1] = \substr($parts[$partCount - 1], 0, $fragStart); + } + + if ($partCount > 1) { $pars = \array_slice($parts, 1); $length = \count($pars); $url = $parts[0]; @@ -214,7 +221,7 @@ final class UriFactory } } - return $url . (!empty($query) ? '?' . \rtrim($query, '&') : ''); + return $url . (!empty($query) ? '?' . \rtrim($query, '&') : '') . $fragment; } /**