Skip to content

Commit

Permalink
Merge pull request #464 from christeredvartsen/issue-463
Browse files Browse the repository at this point in the history
Fixes bug that formats an error model as an image. Close #463.
  • Loading branch information
christeredvartsen committed Apr 14, 2016
2 parents aee8598 + c87b545 commit 992b2e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Imbo-x.x.x
----------
__N/A__

* #463: Fixed issue with an error model being formatted as an image (Christer Edvartsen)
* #444: Added a getData() method to the Imbo\Model\ModelInterface (Christer Edvartsen)
* #431: Added an Amazon S3 storage adapter for the image variations (Ali Asaria)

Expand Down
6 changes: 3 additions & 3 deletions library/Imbo/Http/Response/ResponseFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ public function negotiate(EventInterface $event) {
// instead we want to use the original format of the image
$mime = $model->getMimeType();
$formatter = $this->supportedTypes[$mime];
} else if ($extension && !($model instanceof Model\Error && $routeName === 'image')) {
} else if ($extension && !($model instanceof Model\Error && ($routeName === 'image' || $routeName === 'globalshorturl'))) {
// The user agent wants a specific type. Skip content negotiation completely, but not
// if the request is against the image resource, and ended up as an error, because then
// Imbo would try to render the error as an image.
// if the request is against the image resource (or the global short url resource), and
// ended up as an error, because then Imbo would try to render the error as an image.
$mime = $this->defaultMimeType;

if (isset($this->extensionsToMimeType[$extension])) {
Expand Down
12 changes: 10 additions & 2 deletions tests/phpunit/ImboUnitTest/Http/Response/ResponseFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,20 @@ public function testUsesTheOriginalMimeTypeOfTheImageIfConfigDisablesContentNego
$this->assertSame($expectedFormatter, $this->responseFormatter->getFormatter());
}

public function getImageResources() {
return [
'image' => ['image'],
'global short url' => ['globalshorturl'],
];
}

/**
* @covers Imbo\Http\Response\ResponseFormatter::negotiate
* @dataProvider getImageResources
*/
public function testForcesContentNegotiationOnErrorModelsWhenResourceIsAnImage() {
public function testForcesContentNegotiationOnErrorModelsWhenResourceIsAnImage($routeName) {
$route = new Route();
$route->setName('image');
$route->setName($routeName);

$requestHeaders = $this->getMock('Symfony\Component\HttpFoundation\HeaderBag');
$requestHeaders->expects($this->once())->method('get')->with('Accept', '*/*')->will($this->returnValue('*/*'));
Expand Down

0 comments on commit 992b2e5

Please sign in to comment.