From 69ab4b24df75e6aa79906b9a781f75a7cb0e3832 Mon Sep 17 00:00:00 2001 From: Seb35 Date: Sat, 6 Apr 2019 15:23:57 +0200 Subject: [PATCH] Fix URL encoding in file names Issue: #20 --- packages/sirv/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sirv/index.js b/packages/sirv/index.js index a380c47..116e09a 100644 --- a/packages/sirv/index.js +++ b/packages/sirv/index.js @@ -47,7 +47,7 @@ module.exports = function (dir, opts={}) { if (opts.dev) { return function (req, res, next) { - let uri = req.path || req.pathname || parser(req).pathname; + let uri = decodeURIComponent(req.path || req.pathname || parser(req).pathname); let arr = uri.includes('.') ? [uri] : toAssume(uri, extensions); let file = arr.map(x => join(dir, x)).find(fs.existsSync); if (!file) return next ? next() : notFound(res); @@ -76,7 +76,7 @@ module.exports = function (dir, opts={}) { }); return function (req, res, next) { - let pathname = req.path || req.pathname || parser(req).pathname; + let pathname = decodeURIComponent(req.path || req.pathname || parser(req).pathname); let data = find(pathname, extensions); if (!data) return next ? next() : notFound(res);