Skip to content

Commit 3e96272

Browse files
swillacursoragent
andcommitted
Fix download preview test for Filament href escaping.
Filament 5.6+ HTML-escapes signed URLs in href attributes, so assert the decoded href matches rather than expecting raw ampersands in the rendered HTML. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 974f30a commit 3e96272

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

tests/Unit/LibraryFilePreviewResolverTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,17 @@ function previewMedia(array $attributes, ?string $diskPath = null, ?string $cont
194194
->and($html)->toContain('Paragraph text.');
195195
});
196196

197-
it('renders download preview button with unescaped signed url query params', function (): void {
197+
it('renders download preview button with a valid signed url href', function (): void {
198198
$signedUrl = 'https://example.test/file.txt?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Signature=abc123';
199199

200200
$html = view('filament-library::infolists.components.previews.download', [
201201
'fileUrl' => $signedUrl,
202202
'message' => 'This file type cannot be previewed. Please download to view.',
203203
])->render();
204204

205-
expect($html)->toContain('href="' . $signedUrl . '"')
205+
preg_match('/href="([^"]+)"/', $html, $matches);
206+
207+
expect($matches)->not->toBeEmpty()
208+
->and(html_entity_decode($matches[1], ENT_QUOTES))->toBe($signedUrl)
206209
->and($html)->not->toContain('&amp;amp;');
207210
});

0 commit comments

Comments
 (0)