Skip to content
Myr

throw 400 in case of malformed paths

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

authored by Alex Kocharin · committed by Jonathan Ong · parent 34c83d7 · Browse files · 3 files+52 added−39 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+52 added−39 removed

  • tests:+43 added−17 removed
  • other:+9 added−22 removed

3 files+52 added−39 removed

modified:lib/router/route.js+9 added-3 removed
modified:lib/utils.js-19 removed
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 component320 * 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+43 added-17 removed
25 unmodified lines
26 })27 });28 })2930 describe('decode querystring', function(){30 it('should decode params', function(done){31 var app = express();31 it('should decode correct params', function(done){32 var app = express();3333 app.get('/:name', function(req, res, next){34 res.send(req.params.name);35 });34 app.get('/:name', function(req, res, next){35 res.send(req.params.name);36 });3737 request(app)38 .get('/foo%2Fbar')39 .expect('foo/bar', done);40 })38 request(app)39 .get('/foo%2Fbar')40 .expect('foo/bar', done);41 })4242 it('should accept params in malformed paths', function(done) {43 var app = express();43 it('should not accept params in malformed paths', function(done) {44 var app = express();4545 app.get('/:name', function(req, res, next){46 res.send(req.params.name);47 });46 app.get('/:name', function(req, res, next){47 res.send(req.params.name);48 });4949 request(app)50 .get('/%foobar')51 .expect('%foobar', done);50 request(app)51 .get('/%foobar')52 .expect(400, done);53 })5455 it('should not decode spaces', function(done) {56 var app = express();5758 app.get('/:name', function(req, res, next){59 res.send(req.params.name);60 });6162 request(app)63 .get('/foo+bar')64 .expect('foo+bar', done);65 })6667 it('should work with unicode', function(done) {68 var app = express();6970 app.get('/:name', function(req, res, next){71 res.send(req.params.name);72 });7374 request(app)75 .get('/%ce%b1')76 .expect('\u03b1', done);77 })78 })7980 it('should be .use()able', function(done){81 var app = express();
543 unmodified lines