OPDS Plugin: Ensure the default download filename is consistent across different platforms (#13709)

* Ensure the default download filename is consistent across different platforms.
The OPDS plugin correctly uses util.getSafeFilename() to remove any special characters from the filename for downloads. However this function works differently on different platforms, with some common characters like : and ? being allowed on some platforms but not others. In particular this may break Process Sync if it is configured to rely on file names. This change gives a better default behaviour by ensuring the default filename is the same across different platforms, while still letting the user change the filename to include special characters if the platform supports them.

* Make util.replaceAllInvalidChars() global and call it rather than copying code.
This commit is contained in:
spfenwick authored and GitHub committed 2025-08-16 21:33:01 +02:00
1 parent bfd2bbb15b
commit c00df15aee
2 files changed
+3 -3

No files matched your search

+2 -2
View File
@@ -954,7 +954,7 @@ end
-- <code>/</code> poses a problem.
---- @string str filename
---- @treturn string sanitized filename
local function replaceAllInvalidChars(str)
function util.replaceAllInvalidChars(str)
if str then
str = str:gsub('[\\/:*?"<>|]', '_')
str = str:gsub("[.%s]+$", "")
@@ -984,7 +984,7 @@ If an optional path is provided, @{util.getFilesystemType}() will be used to det
---- @treturn string safe filename
function util.getSafeFilename(str, path, limit, limit_ext)
local filename, suffix = util.splitFileNameSuffix(str)
local replaceFunc = replaceAllInvalidChars
local replaceFunc = util.replaceAllInvalidChars
local safe_filename
-- VFAT supports a maximum of 255 UCS-2 characters, although it's probably treated as UTF-16 by Windows
-- default to a slightly lower limit just in case
+1 -1
View File
@@ -1458,7 +1458,7 @@ function OPDSBrowser:getFileName(item)
if self.root_catalog_raw_names then
filename = nil
end
return filename, filename_orig
return util.replaceAllInvalidChars(filename), util.replaceAllInvalidChars(filename_orig)
end
function OPDSBrowser:updateFieldInCatalog(item, name, value)