Skip to content

Commit d42c769

Browse files
committed
Merge pull request #796 from TV2/hypermedia_multiple_sub_regex
Hypermedia API fails when paths have multiple patterns with sub-regexs
2 parents 0129761 + 5d49a66 commit d42c769

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Router.prototype.render = function render(routeName, params, query) {
181181
return (null);
182182

183183
var _path = route.spec.path;
184-
var _url = _path.replace(/\/:([A-Za-z0-9_]+)(\([^\\]+\))?/g, pathItem);
184+
var _url = _path.replace(/\/:([A-Za-z0-9_]+)(\([^\\]+?\))?/g, pathItem);
185185
var items = Object.keys(query || {}).map(queryItem);
186186
var queryString = items.length > 0 ? ('?' + items.join('&')) : '';
187187
return (_url + queryString);

test/router.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ test('GH #704: render route (with sub-regex param)', function (t) {
8686
t.end();
8787
});
8888

89+
test('GH-796: render route (with multiple sub-regex param)', function (t) {
90+
91+
var server = restify.createServer();
92+
server.get({
93+
name: 'my-route',
94+
path: '/countries/:code([A-Z]{2,3})/:area([0-9]+)'
95+
}, mockResponse);
96+
97+
var link = server.router.render('my-route', {code: '111', area: 42});
98+
t.equal(link, '/countries/111/42');
99+
t.end();
100+
});
89101

90102
test('render route (with encode)', function (t) {
91103

0 commit comments

Comments
 (0)