From 987842ed04e5a7e8025bdfc2ed576d9569eed8ec Mon Sep 17 00:00:00 2001 From: Lars Kiesow Date: Thu, 29 Feb 2024 17:56:55 +0100 Subject: [PATCH] Fix file names with URL control characters This patch ensures that files names like `series #3 xy.jpg` are actually handled correctly instead of the part after `#` being interpreted as fragment and being discarded. I noticed that in a few rare cases the App wouldn't properly display cover images. It turns out that due the file names containing a `#`, the file path got corrupted, causing Audiobookshelf to return a 403. --- server/utils/fileUtils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/utils/fileUtils.js b/server/utils/fileUtils.js index 99bb49ebd5..1fc161c7ff 100644 --- a/server/utils/fileUtils.js +++ b/server/utils/fileUtils.js @@ -357,7 +357,10 @@ module.exports.removeFile = (path) => { } module.exports.encodeUriPath = (path) => { - const uri = new URL(path, "file://") + const uri = new URL('/', "file://") + // we assign the path here to assure that URL control characters like # are + // actually interpreted as part of the URL path + uri.pathname = path return uri.pathname }