Encode parameter values to allow slashes in values, fix #15

pull/20/head
Denis Sokolov 9 years ago committed by Denis
parent 4bd7a135cd
commit 5cc5e5a249

@ -68,10 +68,14 @@ function extractParameters(route, fragment) {
var param = params[i];
if (param) {
if (key[0] === '*') {
param = param.split('/');
param = param.split('/').map(decodeURIComponent);
} else {
param = decodeURIComponent(param);
}
memo[key.substr(1)] = param;
}
@ -88,7 +92,9 @@ function insertParameters(route, obj) {
var value = obj[k] || '';
if (Array.isArray(value)) {
value = value.join('/');
value = value.map(encodeURIComponent).join('/');
} else {
value = encodeURIComponent(value);
}
str = str.replace(route.keys[key], value + '$1');

@ -27,3 +27,19 @@ test('named parameter followed by optional parameter', function(t) {
t.end();
});
test('named parameter with colon in the content', function(t) {
var page = docuri.route('page/:id');
t.deepEqual(page(page({ id: 'value:colon' })), { id: 'value:colon' }, 'parsed page has colon set back correctly');
t.end();
});
test('named parameter with slash in the content', function(t) {
var page = docuri.route('page/:id');
t.deepEqual(page(page({ id: 'value/slash' })), { id: 'value/slash' }, 'parsed page has slash set back correctly');
t.end();
});

Loading…
Cancel
Save