From 3b3e1fc38a8e2763679fc11ff07aed1617946867 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 20 Jun 2015 15:20:35 -0400 Subject: [PATCH] Fix hiding platform issues with decodeURIComponent closes #2652 --- History.md | 2 ++ lib/router/layer.js | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/History.md b/History.md index 5778a23bba..b591d9d0d8 100644 --- a/History.md +++ b/History.md @@ -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` diff --git a/lib/router/layer.js b/lib/router/layer.js index b5c1f58958..a29cf26bfc 100644 --- a/lib/router/layer.js +++ b/lib/router/layer.js @@ -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; } }