Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed May 14, 2017
2 parents 9556d08 + 03436ed commit 69e1885
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Negotiation/Negotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ protected function match(AcceptHeader $accept, AcceptHeader $priority, $index)
list($acceptSub, $acceptPlus) = $this->splitSubPart($acceptSub);
list($prioritySub, $priorityPlus) = $this->splitSubPart($prioritySub);

// If no wildcards in either the subtype or + segment, do nothing.
if (!($acceptBase === '*' || $baseEqual)
|| !($acceptSub === '*' || $prioritySub === '*' || $acceptPlus === '*' || $priorityPlus === '*')
) {
return null;
}

$subEqual = !strcasecmp($acceptSub, $prioritySub);
$plusEqual = !strcasecmp($acceptPlus, $priorityPlus);

if (($acceptBase === '*' || $baseEqual)
&& ($acceptSub === '*' || $subEqual || $acceptPlus === '*' || $plusEqual)
if (($acceptSub === '*' || $prioritySub === '*' || $subEqual)
&& ($acceptPlus === '*' || $priorityPlus === '*' || $plusEqual)
&& count($intersection) === count($accept->getParameters())
) {
$score = 100 * $baseEqual + 10 * $subEqual + $plusEqual + count($intersection);
Expand Down
4 changes: 4 additions & 0 deletions tests/Negotiation/Tests/NegotiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ public static function dataProviderForTestGetBest()
array($rfcHeader, array('text/html;q=0.4', 'text/plain'), array('text/plain', array())),
# Wildcard "plus" parts (e.g., application/vnd.api+json)
array('application/vnd.api+json', array('application/json', 'application/*+json'), array('application/*+json', array())),
array('application/json;q=0.7, application/*+json;q=0.7', array('application/hal+json', 'application/problem+json'), array('application/hal+json', array())),
array('application/json;q=0.7, application/problem+*;q=0.7', array('application/hal+xml', 'application/problem+xml'), array('application/problem+xml', array())),
array($pearAcceptHeader, array('application/*+xml'), array('application/*+xml', array())),
# @see https://github.com/willdurand/Negotiation/issues/93
array('application/hal+json', array('application/ld+json', 'application/hal+json', 'application/xml', 'text/xml', 'application/json', 'text/html'), array('application/hal+json', array())),
);
}

Expand Down

0 comments on commit 69e1885

Please sign in to comment.