Skip to content

Commit

Permalink
Merge pull request #34 from irae/empty-query
Browse files Browse the repository at this point in the history
Only append query if there is something to append
  • Loading branch information
mridgway committed Apr 4, 2016
2 parents 134132e + c3cd82e commit de8796a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Route.prototype.makePath = function (params, query) {
var compiler;
var err;
var url;
var strQuery;

if (Array.isArray(routePath)) {
routePath = routePath[0];
Expand All @@ -161,7 +162,10 @@ Route.prototype.makePath = function (params, query) {
try {
url = compiler(params);
if (query) {
url += '?' + this._queryLib.stringify(query);
strQuery = this._queryLib.stringify(query);
if (strQuery) {
url += '?' + strQuery;
}
}
return url;
} catch (e) {
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ describe('Router', function () {
});
expect(path).to.equal('/foo/bar?baz=foo&foo=bar');
});
it('adds no question mark with empty query', function () {
var path = router.makePath('unamed_params', {
foo: 'foo',
0: 'bar'
}, {/* empty object */});
expect(path).to.equal('/foo/bar');
});
it('non-existing route', function () {
var path = router.makePath('article_does_not_exist', {
site: 'SITE',
Expand Down

0 comments on commit de8796a

Please sign in to comment.