Skip to content
Myr

Merge pull request #1735 from lxe/malformed-capture-route

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Wrapped encodeURIcomponent in try-catch to eliminate errors on malformed captures.

authored by Jonathan Ong · committed by Jonathan Ong · parents 5638a4f, 288176b · Browse files · 3 files+32 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+32 added−1 removed

  • tests:+12 added−0 removed
  • other:+20 added−1 removed

3 files+32 added−1 removed

modified:lib/router/route.js+1 added-1 removed
modified:lib/utils.js+19 added
310 unmodified lines
311 .replace(/([\/.])/g, '\\$1')312 .replace(/\*/g, '(.*)');313 return new RegExp('^' + path + '$', sensitive ? '' : 'i');314}315316317/**318 * Decodes a URI component. Returns319 * the original string if the component 320 * is malformed.321 * 322 * @param {String} str323 * @return {String}324 * @api private325 */326327exports.decode = function(str) {328 try {329 return decodeURIComponent(str);330 } catch (e) { 331 return str;332 }333}
modified:test/app.router.js+12 added
37 unmodified lines
38 .get('/foo%2Fbar')39 .expect('foo/bar', done);40 })4142 it('should accept params in malformed paths', function(done) {43 var app = express();4445 app.get('/:name', function(req, res, next){46 res.send(req.params.name);47 });4849 request(app)50 .get('/%foobar')51 .expect('%foobar', done);52 })5354 it('should be .use()able', function(done){55 var app = express();5657 var calls = [];
541 unmodified lines