Skip to content

Commit

Permalink
Fix Layer#url options to handle encode
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinewyk committed Apr 8, 2020
1 parent ff31e4b commit 78a2929
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ Layer.prototype.captures = function (path) {
Layer.prototype.url = function (params, options) {
var args = params;
var url = this.path.replace(/\(\.\*\)/g, '');
var toPath = compile(url);
var replaced;

if (typeof params != 'object') {
args = Array.prototype.slice.call(arguments);
Expand All @@ -128,6 +126,9 @@ Layer.prototype.url = function (params, options) {
}
}

var toPath = compile(url, options);
var replaced;

var tokens = parse(url);
var replace = {};

Expand Down
5 changes: 4 additions & 1 deletion test/lib/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ describe('Layer', function() {

it('escapes using encodeURIComponent()', function() {
var route = new Layer('/:category/:title', ['get'], [function () {}], {name: 'books'});
var url = route.url({ category: 'programming', title: 'how to node' });
var url = route.url(
{ category: 'programming', title: 'how to node' },
{ encode: encodeURIComponent }
);
url.should.equal('/programming/how%20to%20node');
});
it('setPrefix method checks Layer for path', function () {
Expand Down

0 comments on commit 78a2929

Please sign in to comment.