File tree Expand file tree Collapse file tree 1 file changed +15
-14
lines changed
Expand file tree Collapse file tree 1 file changed +15
-14
lines changed Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments