diff --git a/index.js b/index.js index c942590..e4c9aec 100644 --- a/index.js +++ b/index.js @@ -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'); diff --git a/test/named-parameter-test.js b/test/named-parameter-test.js index 9301d6e..c04b865 100644 --- a/test/named-parameter-test.js +++ b/test/named-parameter-test.js @@ -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(); +});