8000 Uxe HeaderUtils for Content-Disposition · symfony/symfony@7b3d34c · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b3d34c

Browse files
committed
Uxe HeaderUtils for Content-Disposition
1 parent 9b08a46 commit 7b3d34c

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,12 @@ public function makeDisposition($disposition, $filename, $filenameFallback = '')
309309
throw new \InvalidArgumentException('The filename and the fallback cannot contain the "/" and "\\" characters.');
310310
}
311311

312-
$output = sprintf('%s; filename="%s"', $disposition, str_replace('"', '\\"', $filenameFallback));
313-
312+
$params = array('filename' => $filenameFallback);
314313
if ($filename !== $filenameFallback) {
315-
$output .= sprintf("; filename*=utf-8''%s", rawurlencode($filename));
314+
$params['filename*'] = "utf-8''".rawurlencode($filename);
316315
}
317316

318-
return $output;
317+
return $disposition.'; '.HeaderUtils::joinAssoc($params, ';');
319318
}
320319

321320
/**

src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testConstruction()
3232
$response = BinaryFileResponse::create($file, 404, array(), true, ResponseHeaderBag::DISPOSITION_INLINE);
3333
$this->assertEquals(404, $response->getStatusCode());
3434
$this->assertFalse($response->headers->has('ETag'));
35-
$this->assertEquals('inline; filename="README.md"', $response->headers->get('Content-Disposition'));
35+
$this->assertEquals('inline; filename=README.md', $response->headers->get('Content-Disposition'));
3636
}
3737

3838
public function testConstructWithNonAsciiFilename()
@@ -66,7 +66,7 @@ public function testSetContentDispositionGeneratesSafeFallbackFilename()
6666
$response = new BinaryFileResponse(__FILE__);
6767
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'föö.html');
6868

69-
$this->assertSame('attachment; filename="f__.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html', $response->headers->get('Content-Disposition'));
69+
$this->assertSame('attachment; filename=f__.html; filename*=utf-8\'\'f%C3%B6%C3%B6.html', $response->headers->get('Content-Disposition'));
7070
}
7171

7272
public function testSetContentDispositionGeneratesSafeFallbackFilenameForWronglyEncodedFilename()
@@ -77,7 +77,7 @@ public function testSetContentDispositionGeneratesSafeFallbackFilenameForWrongly
7777
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $iso88591EncodedFilename);
7878

7979
// the parameter filename* is invalid in this case (rawurldecode('f%F6%F6') does not provide a UTF-8 string but an ISO-8859-1 encoded one)
80-
$this->assertSame('attachment; filename="f__.html"; filename*=utf-8\'\'f%F6%F6.html', $response->headers->get('Content-Disposition'));
80+
$this->assertSame('attachment; filename=f__.html; filename*=utf-8\'\'f%F6%F6.html', $response->headers->get('Content-Disposition'));
8181
}
8282

8383
/**

src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ public function testToStringDoesntMessUpHeaders()
276276
public function provideMakeDisposition()
277277
{
278278
return array(
279-
array('attachment', 'foo.html', 'foo.html', 'attachment; filename="foo.html"'),
280-
array('attachment', 'foo.html', '', 'attachment; filename="foo.html"'),
279+
array('attachment', 'foo.html', 'foo.html', 'attachment; filename=foo.html'),
280+
array('attachment', 'foo.html', '', 'attachment; filename=foo.html'),
281281
array('attachment', 'foo bar.html', '', 'attachment; filename="foo bar.html"'),
282282
array('attachment', 'foo "bar".html', '', 'attachment; filename="foo \\"bar\\".html"'),
283283
array('attachment', 'foo%20bar.html', 'foo bar.html', 'attachment; filename="foo bar.html"; filename*=utf-8\'\'foo%2520bar.html'),
284-
array('attachment', 'föö.html', 'foo.html', 'attachment; filename="foo.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html'),
284+
array('attachment', 'föö.html', 'foo.html', 'attachment; filename=foo.html; filename*=utf-8\'\'f%C3%B6%C3%B6.html'),
285285
);
286286
}
287287

0 commit comments

Comments
 (0)
0