Socket
Socket
Sign inDemoInstall

koa-router

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-router - npm Package Compare versions

Comparing version 3.1.2 to 3.1.3

20

lib/route.js

@@ -87,3 +87,3 @@ /**

var c = captures[i];
params[this.params[i].name] = c ? decodeURIComponent(c) : c;
params[this.params[i].name] = c ? safeDecodeURIComponent(c) : c;
}

@@ -95,3 +95,3 @@ }

var c = captures[i];
params[i] = c ? decodeURIComponent(c) : c;
params[i] = c ? safeDecodeURIComponent(c) : c;
}

@@ -147,1 +147,17 @@ }

};
/**
* Safe decodeURIComponent, won't throw any error.
* If `decodeURIComponent` error happen, just return the original value.
*
* @param {String} text
* @return {String} URL decode original string.
*/
function safeDecodeURIComponent(text) {
try {
return decodeURIComponent(text);
} catch (e) {
return text;
}
}

2

package.json

@@ -9,3 +9,3 @@ {

"author": "Alex Mingoia <talk@alexmingoia.com>",
"version": "3.1.2",
"version": "3.1.3",
"keywords": [

@@ -12,0 +12,0 @@ "koa",

@@ -71,2 +71,18 @@ /**

it('return orginal path parameters when decodeURIComponent throw error', function(done) {
var app = koa();
app.use(router(app));
app.get('/:category/:title', function *(next) {
this.should.have.property('params');
this.params.should.be.type('object');
this.params.should.have.property('category', '100%');
this.params.should.have.property('title', '101%');
this.status = 204;
});
request(http.createServer(app.callback()))
.get('/100%/101%')
.expect(204)
.end(done);
});
it('populates ctx.params with regexp captures', function(done) {

@@ -95,4 +111,26 @@ var app = koa();

it('should populates ctx.params with regexp captures include undefiend', function(done) {
it('return orginal ctx.params when decodeURIComponent throw error', function(done) {
var app = koa();
app.use(router(app));
app.get(/^\/api\/([^\/]+)\/?/i, function *(next) {
this.should.have.property('params');
this.params.should.be.type('object');
this.params.should.have.property(0, '101%');
yield next;
}, function *(next) {
this.should.have.property('params');
this.params.should.be.type('object');
this.params.should.have.property(0, '101%');
this.status = 204;
});
request(http.createServer(app.callback()))
.get('/api/101%')
.expect(204)
.end(function(err) {
if (err) return done(err);
done();
});
});
it('populates ctx.params with regexp captures include undefiend', function(done) {
var app = koa();

@@ -99,0 +137,0 @@ app.use(router(app));

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc