@@ -23,26 +23,37 @@ public function testHeaders(): void {
2323 $ response = new ChildDownloadResponse ('file ' , 'content ' );
2424 $ headers = $ response ->getHeaders ();
2525
26- $ this ->assertEquals ('attachment; filename=" file" ' , $ headers ['Content-Disposition ' ]);
26+ $ this ->assertEquals ('attachment; filename=file ' , $ headers ['Content-Disposition ' ]);
2727 $ this ->assertEquals ('content ' , $ headers ['Content-Type ' ]);
2828 }
2929
3030 #[\PHPUnit \Framework \Attributes \DataProvider('filenameEncodingProvider ' )]
31- public function testFilenameEncoding (string $ input , string $ expected ): void {
31+ public function testFilenameEncoding (string $ input , string $ expectedDisposition ): void {
3232 $ response = new ChildDownloadResponse ($ input , 'content ' );
3333 $ headers = $ response ->getHeaders ();
3434
35- $ this ->assertEquals (' attachment; filename=" ' . $ expected . ' " ' , $ headers ['Content-Disposition ' ]);
35+ $ this ->assertEquals ($ expectedDisposition , $ headers ['Content-Disposition ' ]);
3636 }
3737
38- public static function filenameEncodingProvider () : array {
38+ public static function filenameEncodingProvider (): array {
3939 return [
40- ['TestName.txt ' , 'TestName.txt ' ],
41- ['A "Quoted" Filename.txt ' , 'A \\ "Quoted \\ " Filename.txt ' ],
42- ['A "Quoted" Filename.txt ' , 'A \\ "Quoted \\ " Filename.txt ' ],
43- ['A "Quoted" Filename With A Backslash \\.txt ' , 'A \\ "Quoted \\ " Filename With A Backslash \\\\ .txt ' ],
44- ['A "Very" Weird Filename \ / & <> " > \'""""\.text ' , 'A \\ "Very \\ " Weird Filename \\\\ / & <> \\ " > \'\\ " \\ " \\ " \\ " \\\\ .text ' ],
45- ['\\\\\\\\\\\\' , '\\\\\\\\\\\\\\\\\\\\\\\\ ' ],
40+ ['TestName.txt ' , 'attachment; filename= TestName.txt ' ],
41+ ['A "Quoted" Filename.txt ' , 'attachment; filename=" A \"Quoted\" Filename.txt" ' ],
42+ ['A "Quoted" Filename.txt ' , 'attachment; filename=" A \"Quoted\" Filename.txt" ' ],
43+ ['A "Quoted" Filename With A Backslash \\.txt ' , 'attachment; filename=" A \"Quoted\" Filename With A Backslash - .txt" ' ],
44+ ['A "Very" Weird Filename \ / & <> " > \'""""\.text ' , 'attachment; filename=" A \"Very\" Weird Filename - - & <> \" > \'\"\"\"\"- .text" ' ],
45+ ['\\\\\\\\\\\\' , 'attachment; filename=------ ' ],
4646 ];
4747 }
48+
49+ public function testSpecialCharactersInFilename (): void {
50+ $ filename = 'document "draft" with; special&chars.pdf ' ;
51+ $ response = new ChildDownloadResponse ($ filename , 'application/pdf ' );
52+ $ headers = $ response ->getHeaders ();
53+
54+ $ this ->assertEquals (
55+ 'attachment; filename="document \"draft\" with; special&chars.pdf" ' ,
56+ $ headers ['Content-Disposition ' ]
57+ );
58+ }
4859}
0 commit comments