Skip to content

Commit

Permalink
Check quality > 0.0 in FormatNegotiator::getBestFormat()
Browse files Browse the repository at this point in the history
The getBestFormat() method returns a format or null. When quality == 0.0,
then it should return null rather than the negotiated format.

Fix #29

See: #29
  • Loading branch information
willdurand committed May 16, 2014
1 parent 8f8c85f commit 94733e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Negotiation/FormatNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public function getBestFormat($acceptHeader, array $priorities = array())
$catchAllEnabled = $this->isCatchAllEnabled($priorities);

if (null !== $accept = $this->getBest($acceptHeader, $mimeTypes)) {
if (null !== $format = $this->getFormat($accept->getValue())) {
if (0.0 < $accept->getQuality() &&
null !== $format = $this->getFormat($accept->getValue())
) {
if (in_array($format, $priorities) || $catchAllEnabled) {
return $format;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Negotiation/Tests/FormatNegotiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public static function dataProviderForGetBestFormat()
array('text/html,application/xhtml+xml,application/xml', array('json'), null),
array('text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c', array('*/*'), 'html'),
array('text/html, application/json;q=0.8, text/csv;q=0.7', array(), 'html'),
array('text/html; q=0.0', array(), null),
);
}

Expand Down

3 comments on commit 94733e9

@coreation
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 👍

@willdurand
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

@willdurand
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all versions are "impacted"

Please sign in to comment.