Skip to content

Commit 146ebbb

Browse files
* Fix laravel/framework#57456 * Fix laravel/framework#57456 * Fix laravel/framework#57456 * Fix laravel/framework#57456 * Fix laravel/framework#57456 --------- Co-authored-by: Pantea Marius-ciclistu <>
1 parent a9f7b21 commit 146ebbb

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

illuminate/Routing/UrlGenerator.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,34 +162,35 @@ public function current()
162162
*/
163163
public function previous($fallback = false)
164164
{
165-
$referrer = $this->request->headers->get('referer');
165+
$fallback = (string)$fallback;
166+
$referrer = (string)$this->request->headers->get('referer');
166167

167-
$url = $referrer ? $this->to($referrer) : $this->getPreviousUrlFromSession();
168+
if ('' === $referrer) {
169+
$referrer = (string)$this->getPreviousUrlFromSession();
170+
}
168171

169-
if ($url) {
170-
return $url;
171-
} elseif ($fallback) {
172-
return $this->to($fallback);
172+
if ('' === $referrer) {
173+
return (string)$this->to('' === $fallback ? '/' : $fallback);
173174
}
174175

175-
return $this->to('/');
176+
$previous = (string)$this->to($referrer);
177+
178+
return '' !== $previous ? $previous : (string)$this->to('' === $fallback ? '/' : $fallback);
176179
}
177180

178181
/**
179-
* Get the previous path info for the request.
182+
* Get the previous path for the request.
180183
*
181184
* @param mixed $fallback
182185
* @return string
183186
*/
184187
public function previousPath($fallback = false)
185188
{
186-
$previousPath = str_replace(
187-
$this->to('/'),
188-
'',
189-
rtrim(preg_replace('/\?.*/', '', $this->previous($fallback)), '/')
190-
);
189+
if (!\is_string($path = \parse_url($this->previous($fallback), PHP_URL_PATH))) {
190+
return '/';
191+
}
191192

192-
return $previousPath === '' ? '/' : $previousPath;
193+
return $path === '/' ? $path : \rtrim($path, '/');
193194
}
194195

195196
/**

0 commit comments

Comments
 (0)