Skip to content

Commit

Permalink
Fix hiding platform issues with decodeURIComponent
Browse files Browse the repository at this point in the history
closes #2652
  • Loading branch information
dougwilson committed Jun 20, 2015
1 parent 5915894 commit 3b3e1fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ unreleased

* Fix `res.format` error when only `default` provided
* Fix issue where `next('route')` in `app.param` would incorrectly skip values
* Fix hiding platform issues with `decodeURIComponent`
- Only `URIError`s are a 400
* Fix using `*` before params in routes
* Fix using capture groups before params in routes
* Simplify `res.cookie` to call `res.append`
Expand Down
13 changes: 8 additions & 5 deletions lib/router/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,22 @@ Layer.prototype.match = function match(path) {
*
* @param {string} val
* @return {string}
* @api private
* @private
*/

function decode_param(val){
function decode_param(val) {
if (typeof val !== 'string') {
return val;
}

try {
return decodeURIComponent(val);
} catch (e) {
var err = new TypeError("Failed to decode param '" + val + "'");
err.status = 400;
} catch (err) {
if (err instanceof URIError) {
err.message = 'Failed to decode param \'' + val + '\'';
err.status = 400;
}

throw err;
}
}

0 comments on commit 3b3e1fc

Please sign in to comment.