-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure generated query strings are consistent
PHP configuration can be modified to set a different argument separator from the standard `&`. Generated query strings should always use the standard separator. Fixes #519
- Loading branch information
1 parent
317812a
commit addfc24
Showing
4 changed files
with
73 additions
and
4 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
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,33 @@ | ||
<?php | ||
/** | ||
* This file is part of the league/oauth2-client library | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Alex Bilbie <[email protected]> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
* @link http://thephpleague.com/oauth2-client/ Documentation | ||
* @link https://packagist.org/packages/league/oauth2-client Packagist | ||
* @link https://github.com/thephpleague/oauth2-client GitHub | ||
*/ | ||
|
||
namespace League\OAuth2\Client\Tool; | ||
|
||
/** | ||
* Provides a standard way to generate query strings. | ||
*/ | ||
trait QueryBuilderTrait | ||
{ | ||
/** | ||
* Build a query string from an array. | ||
* | ||
* @param array $params | ||
* | ||
* @return string | ||
*/ | ||
protected function buildQueryString(array $params) | ||
{ | ||
return http_build_query($params, null, '&'); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Client\Test\Tool; | ||
|
||
use League\OAuth2\Client\Tool\QueryBuilderTrait; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
class QueryBuilderTraitTest extends PHPUnit_Framework_TestCase | ||
{ | ||
use QueryBuilderTrait; | ||
|
||
public function setUp() | ||
{ | ||
ini_set('arg_separator.output', '&'); | ||
} | ||
|
||
public function testBuildQueryString() | ||
{ | ||
$params = [ | ||
'a' => 'foo', | ||
'b' => 'bar', | ||
]; | ||
|
||
$query = $this->buildQueryString($params); | ||
|
||
$this->assertSame('a=foo&b=bar', $query); | ||
} | ||
} |