From c00df15aeee73b4fdb0475d26fd3fa3c315f3f8f Mon Sep 17 00:00:00 2001 From: spfenwick <101789313+spfenwick@users.noreply.github.com> Date: Sun, 17 Aug 2025 07:33:01 +1200 Subject: [PATCH] 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. --- frontend/util.lua | 4 ++-- plugins/opds.koplugin/opdsbrowser.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/util.lua b/frontend/util.lua index 65e306009..c1e97502f 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -954,7 +954,7 @@ end -- / 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 diff --git a/plugins/opds.koplugin/opdsbrowser.lua b/plugins/opds.koplugin/opdsbrowser.lua index f4b808577..46882a5cd 100644 --- a/plugins/opds.koplugin/opdsbrowser.lua +++ b/plugins/opds.koplugin/opdsbrowser.lua @@ -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)