forked from zfcampus/zf-content-negotiation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Per a number of reports, some modules were using dash-separated keys instead of underscore_separated keys for content-negotiation options. zf-content-negotiation was ignoring these previously, but starting with 1.2.0 and the introduction of the ContentNegotiationOptions class, these are now invalid and raise an exception, breaking applications. The specific module in question is likely zf-apigility-doctrine, and there's a PR against that repo to fix it: zfcampus/zf-apigility-doctrine#212. This patch modifies the options class to munge dash-separated values to ensure they work.
- Loading branch information
1 parent
c89a07b
commit 5629be5
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com) | ||
*/ | ||
|
||
namespace ZFTest\ContentNegotiation; | ||
|
||
use PHPUnit_Framework_TestCase as TestCase; | ||
use ZF\ContentNegotiation\ContentNegotiationOptions; | ||
|
||
class ContentNegotiationOptionsTest extends TestCase | ||
{ | ||
public function dashSeparatedOptions() | ||
{ | ||
return [ | ||
'accept-whitelist' => ['accept-whitelist', 'accept_whitelist'], | ||
'content-type-whitelist' => ['content-type-whitelist', 'content_type_whitelist'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider dashSeparatedOptions | ||
*/ | ||
public function testSetNormalizesDashSeparatedKeysToUnderscoreSeparated($key, $normalized) | ||
{ | ||
$options = new ContentNegotiationOptions(); | ||
$options->{$key} = ['value']; | ||
$this->assertEquals(['value'], $options->{$key}); | ||
$this->assertEquals(['value'], $options->{$normalized}); | ||
} | ||
|
||
/** | ||
* @dataProvider dashSeparatedOptions | ||
*/ | ||
public function testConstructorAllowsDashSeparatedKeys($key, $normalized) | ||
{ | ||
$options = new ContentNegotiationOptions([$key => ['value']]); | ||
$this->assertEquals(['value'], $options->{$key}); | ||
$this->assertEquals(['value'], $options->{$normalized}); | ||
} | ||
} |