fix: Escape URL in generate_href_html() output (#19428)

This commit is contained in:
RenHai Wen
2026-03-05 16:27:40 +00:00
committed by GitHub
parent 072a7d0a1a
commit d30efb2fb3
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -133,7 +133,7 @@ if (! function_exists('Filament\Support\generate_href_html')) {
return new HtmlString('');
}
$html = "href=\"{$url}\"";
$html = 'href="' . e($url) . '"';
if ($shouldOpenInNewTab) {
$html .= ' target="_blank"';
@@ -141,7 +141,7 @@ if (! function_exists('Filament\Support\generate_href_html')) {
if (FilamentView::hasSpaPrefetching()) {
$html .= ' wire:navigate.hover';
} elseif ($hasNestedClickEventHandler) {
$html .= ' x-on:click="if (! ($event.altKey || $event.ctrlKey || $event.metaKey || $event.shiftKey)) { $event.preventDefault(); Alpine.navigate(' . "'{$url}'" . ') }"';
$html .= ' x-on:click="if (! ($event.altKey || $event.ctrlKey || $event.metaKey || $event.shiftKey)) { $event.preventDefault(); Alpine.navigate($el.getAttribute(\'href\')) }"';
} else {
$html .= ' wire:navigate';
}
+2 -2
View File
@@ -196,7 +196,7 @@ test('`hasNestedClickEventHandler` forces Alpine navigation when SPA mode is ena
FilamentView::spa(true, false);
expect(generate_href_html('http://localhost/page', hasNestedClickEventHandler: true))
->toHtml()->toBe('href="http://localhost/page" x-on:click="if (! ($event.altKey || $event.ctrlKey || $event.metaKey || $event.shiftKey)) { $event.preventDefault(); Alpine.navigate(\'http://localhost/page\') }"');
->toHtml()->toBe('href="http://localhost/page" x-on:click="if (! ($event.altKey || $event.ctrlKey || $event.metaKey || $event.shiftKey)) { $event.preventDefault(); Alpine.navigate($el.getAttribute(\'href\')) }"');
expect(generate_href_html('http://localhost/page', hasNestedClickEventHandler: false))
->toHtml()->toBe('href="http://localhost/page" wire:navigate');
@@ -236,7 +236,7 @@ test('`hasNestedClickEventHandler` works with `shouldOpenInSpaMode` parameter ov
FilamentView::spa(false);
expect(generate_href_html('http://localhost/page', shouldOpenInSpaMode: true, hasNestedClickEventHandler: true))
->toHtml()->toBe('href="http://localhost/page" x-on:click="if (! ($event.altKey || $event.ctrlKey || $event.metaKey || $event.shiftKey)) { $event.preventDefault(); Alpine.navigate(\'http://localhost/page\') }"');
->toHtml()->toBe('href="http://localhost/page" x-on:click="if (! ($event.altKey || $event.ctrlKey || $event.metaKey || $event.shiftKey)) { $event.preventDefault(); Alpine.navigate($el.getAttribute(\'href\')) }"');
expect(generate_href_html('http://localhost/page', shouldOpenInSpaMode: true, hasNestedClickEventHandler: false))
->toHtml()->toBe('href="http://localhost/page" wire:navigate');