fix(backurl): avoid double fragment when using withBackAndFragment

This commit is contained in:
萝卜
2026-03-14 21:33:32 +00:00
parent 4e741b92a1
commit ee85e63340
2 changed files with 25 additions and 0 deletions

View File

@@ -152,6 +152,11 @@ class BackUrl
*/
public static function withBackAndFragment(string $path, string $safeBackForLinks = '', string $fragment = ''): string
{
// 若调用方传入了 path 自带 fragment同时又传入 fragment 参数,避免出现 "#old#new"。
if ((string) $fragment !== '' && str_contains((string) $path, '#')) {
[$path] = explode('#', (string) $path, 2);
}
$url = self::withBack($path, $safeBackForLinks);
$fragment = ltrim((string) $fragment, '#');