@@ -30,22 +30,36 @@ class ChildDownloadResponse extends DownloadResponse {
3030
3131
3232class DownloadResponseTest extends \Test \TestCase {
33-
34- /**
35- * @var ChildDownloadResponse
36- */
37- protected $ response ;
38-
3933 protected function setUp (): void {
4034 parent ::setUp ();
41- $ this ->response = new ChildDownloadResponse ('file ' , 'content ' );
4235 }
4336
44-
4537 public function testHeaders () {
46- $ headers = $ this ->response ->getHeaders ();
38+ $ response = new ChildDownloadResponse ('file ' , 'content ' );
39+ $ headers = $ response ->getHeaders ();
40+
41+ $ this ->assertEquals ('attachment; filename="file" ' , $ headers ['Content-Disposition ' ]);
42+ $ this ->assertEquals ('content ' , $ headers ['Content-Type ' ]);
43+ }
44+
45+ /**
46+ * @dataProvider filenameEncodingProvider
47+ */
48+ public function testFilenameEncoding (string $ input , string $ expected ) {
49+ $ response = new ChildDownloadResponse ($ input , 'content ' );
50+ $ headers = $ response ->getHeaders ();
51+
52+ $ this ->assertEquals ('attachment; filename=" ' .$ expected .'" ' , $ headers ['Content-Disposition ' ]);
53+ }
4754
48- $ this ->assertStringContainsString ('attachment; filename="file" ' , $ headers ['Content-Disposition ' ]);
49- $ this ->assertStringContainsString ('content ' , $ headers ['Content-Type ' ]);
55+ public function filenameEncodingProvider () : array {
56+ return [
57+ ['TestName.txt ' , 'TestName.txt ' ],
58+ ['A "Quoted" Filename.txt ' , 'A \\"Quoted \\" Filename.txt ' ],
59+ ['A "Quoted" Filename.txt ' , 'A \\"Quoted \\" Filename.txt ' ],
60+ ['A "Quoted" Filename With A Backslash \\.txt ' , 'A \\"Quoted \\" Filename With A Backslash \\\\.txt ' ],
61+ ['A "Very" Weird Filename \ / & <> " > \'""""\.text ' , 'A \\"Very \\" Weird Filename \\\\ / & <> \\" > \'\\" \\" \\" \\" \\\\.text ' ],
62+ ['\\\\\\\\\\\\' , '\\\\\\\\\\\\\\\\\\\\\\\\' ],
63+ ];
5064 }
5165}
0 commit comments