Skip to content

Commit

Permalink
fix: allow encoded URI components in URL parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Jun 29, 2016
1 parent f8da5a2 commit ae1ad85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions modules/Path.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const defaultOrConstrained = (match) =>
'(' + (match ? match.replace(/(^<|>$)/g, '') : '[a-zA-Z0-9-_.~]+') + ')';
'(' + (match ? match.replace(/(^<|>$)/g, '') : '[a-zA-Z0-9-_.~%]+') + ')';

const rules = [
{
Expand Down Expand Up @@ -166,7 +166,7 @@ export default class Path {
// Reduce named params to key-value pairs
return match.slice(1, this.urlParams.length + 1)
.reduce((params, m, i) => {
params[this.urlParams[i]] = m;
params[this.urlParams[i]] = decodeURIComponent(m);
return params;
}, {});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/commonjs/path-parser.js",
"jsnext:main": "modules/Path.js",
"scripts": {
"test": "_mocha",
"test": "mocha --compilers js:babel-core/register",
"test-cover": "istanbul cover _mocha",
"lint": "eslint modules/*.js",
"build:amd": "BABEL_ENV=rollup rollup -c rollup.config.js --format amd",
Expand Down
8 changes: 7 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var path = require('path');
var pkg = require('../package.json');
var Path = require(path.join(__dirname, '..', pkg.main));
var Path = require('../modules/Path');
var should = require('should');

require('mocha');
Expand Down Expand Up @@ -168,4 +168,10 @@ describe('Path', function () {
path.match('/', true).should.eql({});
path.match('', 1).should.eql({});
});

it('should match paths with encoded values', function () {
var path = new Path('/test/:id');

path.partialMatch('/test/%7B123-456%7D').should.eql({ id: '{123-456}' });
});
});

0 comments on commit ae1ad85

Please sign in to comment.