From b00cd65ef3f16f40baf83d5649a54cd5c8fe8854 Mon Sep 17 00:00:00 2001 From: Vladislav Lyshenko Date: Thu, 16 Mar 2017 13:15:05 +0200 Subject: [PATCH] Fixes #13738: Fixed `getQueryParams()` method in `yii.js` to correctly parse URL with question mark and no query parameters --- framework/CHANGELOG.md | 1 + framework/assets/yii.js | 6 ++++-- tests/js/tests/yii.gridView.test.js | 6 ++++++ tests/js/tests/yii.test.js | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index b4ae6073a6..c231784a41 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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 -------------------------- diff --git a/framework/assets/yii.js b/framework/assets/yii.js index 8873069159..f5616636d0 100644 --- a/framework/assets/yii.js +++ b/framework/assets/yii.js @@ -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('='); diff --git a/tests/js/tests/yii.gridView.test.js b/tests/js/tests/yii.gridView.test.js index d166d33f7f..f5e1711dfd 100644 --- a/tests/js/tests/yii.gridView.test.js +++ b/tests/js/tests/yii.gridView.test.js @@ -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', diff --git a/tests/js/tests/yii.test.js b/tests/js/tests/yii.test.js index bf7da4d202..07aae73bed 100644 --- a/tests/js/tests/yii.test.js +++ b/tests/js/tests/yii.test.js @@ -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']}],