koa-router
Advanced tools
Comparing version 3.1.2 to 3.1.3
@@ -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; | ||
} | ||
} |
@@ -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)); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31373
841