When using Express' URL parameter functionality, it seems that parameters are automatically decoded. That is, percent-encoded entities are resolved to their normal form. %20
is replaced with a space.
However, a plus +
is not replaced with a space. This is presumably because Express is using decodeURIComponent()
internally, which also does not replace plus +
with a space. Simple example code:
app.get('/:sourceFile', function (req, res, next) {
console.log(req.params.sourceFile);
});
If you request /test%20test
, then you get test test
on the console. If you request /test+test
, then you get test+test
on the console.
Is there a way to change this mode of operation in Express 4? Is this a bug?
router/layer.js
, usingdecodeURIComponent()
as you suspected, and I don't see any options to modify that behavior (decode_param
is defined and referenced only as a local within the module scope) without a PR. – Zephan+
with%20
, but it's a bit hacky. – Bravar