Fixes #13738: Fixed getQueryParams() method in yii.js to correctly parse URL with question mark and no query parameters

This commit is contained in:
Vladislav Lyshenko
2017-03-16 13:15:05 +02:00
committed by Alexander Makarov
parent bc59d5da85
commit b00cd65ef3
4 changed files with 13 additions and 2 deletions

View File

@ -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
--------------------------

View File

@ -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('=');

View File

@ -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',

View File

@ -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']}],