From 78a292925594f6acb6def50723094467e7c2c413 Mon Sep 17 00:00:00 2001 From: sinewyk Date: Wed, 8 Apr 2020 22:04:44 +0200 Subject: [PATCH] Fix Layer#url options to handle encode --- lib/layer.js | 5 +++-- test/lib/layer.js | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/layer.js b/lib/layer.js index 46c6954..5311267 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -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); @@ -128,6 +126,9 @@ Layer.prototype.url = function (params, options) { } } + var toPath = compile(url, options); + var replaced; + var tokens = parse(url); var replace = {}; diff --git a/test/lib/layer.js b/test/lib/layer.js index fcf6afc..3508e44 100644 --- a/test/lib/layer.js +++ b/test/lib/layer.js @@ -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 () {