From 8db0dee5e07343bfb9af845d69a73734366dc5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mnich?= Date: Sun, 13 Jul 2025 22:34:17 +0200 Subject: [PATCH] [fix] Improve handling of illegal vFAT filenames. (#14043) This change fixes an issue where a file/directory is not created when its name contains trailing spaces or dots. The issue has been observed on a Kobo device, but probably also applies to other systems using vFAT. We also might want to consider handling other illegal vFAT filenames like `NUL` or `AUX`. Please see the [official Microsoft documentation](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions) for more details on the naming conventions of vFAT (this change addresses the last bullet point). --- frontend/util.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/util.lua b/frontend/util.lua index 7e22edddf..65e306009 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -948,14 +948,17 @@ end --- Replaces characters that are invalid filenames. -- --- Replaces the characters \/:*?"<>| with an _. +-- Replaces the characters \/:*?"<>| with an _ +-- and removes trailing dots and spaces, in line with . -- These characters are problematic on Windows filesystems. On Linux only -- / poses a problem. ---- @string str filename ---- @treturn string sanitized filename local function replaceAllInvalidChars(str) if str then - return str:gsub('[\\/:*?"<>|]', '_') + str = str:gsub('[\\/:*?"<>|]', '_') + str = str:gsub("[.%s]+$", "") + return str end end