Skip to content

Commit

Permalink
Fixes yiisoft#13738: Fixed getQueryParams() method in yii.js to c…
Browse files Browse the repository at this point in the history
…orrectly parse URL with question mark and no query parameters
  • Loading branch information
vladdnepr authored and samdark committed Mar 16, 2017
1 parent bc59d5d commit b00cd65
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Yii Framework 2 Change Log
- Enh #13254: Core validators no longer require Yii::$app to be set (sammousa)
- Bug #4408: Add support for unicode word characters and `+` character in attribute names (sammousa, kmindi)
- Bug #10372: Fixed console controller including complex typed arguments in help (sammousa)
- Bug #13738: Fixed `getQueryParams()` method in `yii.js` to correctly parse URL with question mark and no query parameters (vladdnepr)

2.0.11.2 February 08, 2017
--------------------------
Expand Down
6 changes: 4 additions & 2 deletions framework/assets/yii.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,10 @@ window.yii = (function ($) {
return {};
}

var pairs = url.substring(pos + 1).split('#')[0].split('&'),
params = {};
var pairs = $.grep(url.substring(pos + 1).split('#')[0].split('&'), function (value) {
return value !== '';
});
var params = {};

for (var i = 0, len = pairs.length; i < len; i++) {
var pair = pairs[i].split('=');
Expand Down
6 changes: 6 additions & 0 deletions tests/js/tests/yii.gridView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ describe('yii.gridView', function () {
describe('with different urls', function () {
describe('with no filter data sent', function () {
withData({
// https://github.com/yiisoft/yii2/issues/13738
'question mark, no query parameters': [
'/posts/index?',
'/posts/index',
'PostSearch[name]=&PostSearch[category_id]='
],
'query parameters': [
'/posts/index?foo=1&bar=2',
'/posts/index',
Expand Down
2 changes: 2 additions & 0 deletions tests/js/tests/yii.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ describe('yii', function () {
describe('getQueryParams method', function () {
withData({
'no query parameters': ['/posts/index', {}],
// https://github.com/yiisoft/yii2/issues/13738
'question mark, no query parameters': ['/posts/index?', {}],
'query parameters': ['/posts/index?foo=1&bar=2', {foo: '1', bar: '2'}],
'query parameter with multiple values (not array)': ['/posts/index?foo=1&foo=2', {'foo': ['1', '2']}],
'query parameter with multiple values (array)': ['/posts/index?foo[]=1&foo[]=2', {'foo[]': ['1', '2']}],
Expand Down

0 comments on commit b00cd65

Please sign in to comment.