Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only append query if there is something to append #34

Merged
merged 1 commit into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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