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.
This commit is contained in:
Lars Kiesow 2024-02-29 17:56:55 +01:00
parent d2b006b909
commit 987842ed04
No known key found for this signature in database
GPG Key ID: 5DAFE8D9C823CE73

View File

@ -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
}