From 4090b1fd2606caefc0aecc5e2563fa48ac726923 Mon Sep 17 00:00:00 2001 From: Stuart Colville Date: Wed, 26 Mar 2014 10:21:40 +0000 Subject: [PATCH] Uplift from mozilla/fireplace#409 --- src/media/js/navigation.js | 8 +++++--- src/templates/tests.html | 1 + src/tests/navigation.js | 12 ++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 src/tests/navigation.js diff --git a/src/media/js/navigation.js b/src/media/js/navigation.js index 61d60e8..03789b5 100644 --- a/src/media/js/navigation.js +++ b/src/media/js/navigation.js @@ -21,9 +21,10 @@ define('navigation', return url; } - var used_params = _.pick(utils.querystring(url), settings.param_whitelist); // We can't use urlparams() because that only extends, not replaces. - return utils.baseurl(url) + '?' + utils.urlencode(used_params); + var used_params = _.pick(utils.querystring(url), settings.param_whitelist); + var queryParams = utils.urlencode(used_params); + return utils.baseurl(url) + (queryParams.length ? '?' + queryParams : ''); } function canNavigate() { @@ -224,7 +225,8 @@ define('navigation', return { 'back': back, 'stack': function() {return stack;}, - 'navigationFilter': navigationFilter + 'navigationFilter': navigationFilter, + 'extract_nav_url': extract_nav_url }; }); diff --git a/src/templates/tests.html b/src/templates/tests.html index a0a6648..0a0992c 100644 --- a/src/templates/tests.html +++ b/src/templates/tests.html @@ -19,6 +19,7 @@ + diff --git a/src/tests/navigation.js b/src/tests/navigation.js new file mode 100644 index 0000000..a1b8c2f --- /dev/null +++ b/src/tests/navigation.js @@ -0,0 +1,12 @@ +(function() { + var a = require('assert'); + var assert = a.assert; + var eq_ = a.eq_; + + var navigation = require('navigation'); + test('navigation url extraction', function(done) { + eq_(navigation.extract_nav_url('/foo/bar?src=all-popular'), '/foo/bar'); + eq_(navigation.extract_nav_url('/foo/bar?src=all-popular&q=bar'), '/foo/bar?q=bar'); + done(); + }); +})();