mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
fix: Escape URL in generate_href_html() output (#19428)
This commit is contained in:
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user