Skip to content

Commit

Permalink
[HttpFoundation] Added check for disposition value
Browse files Browse the repository at this point in the history
  • Loading branch information
jalliot committed Sep 8, 2011
1 parent 49e1eee commit 0bc2a6d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php
Expand Up @@ -20,8 +20,11 @@
*/
class ResponseHeaderBag extends HeaderBag
{
const COOKIES_FLAT = 'flat';
const COOKIES_ARRAY = 'array';
const COOKIES_FLAT = 'flat';
const COOKIES_ARRAY = 'array';

const DISPOSITION_ATTACHMENT = 'attachment';
const DISPOSITION_INLINE = 'inline';

protected $computedCacheControl = array();
protected $cookies = array();
Expand Down Expand Up @@ -216,6 +219,10 @@ public function clearCookie($name, $path = null, $domain = null)
*/
public function makeDisposition($disposition, $filename, $filenameFallback = '')
{
if (!in_array($disposition, array(self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE))) {
throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
}

if (!$filenameFallback) {
$filenameFallback = $filename;
}
Expand Down
Expand Up @@ -119,6 +119,16 @@ public function testRemoveCookie()
$this->assertFalse(isset($cookies['foo.bar']));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testMakeDispositionInvalidDisposition()
{
$headers = new ResponseHeaderBag();

$headers->makeDisposition('invalid', 'foo.html');
}

/**
* @dataProvider provideMakeDisposition
*/
Expand Down

0 comments on commit 0bc2a6d

Please sign in to comment.