[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).
This commit is contained in:
1 parent
9b07f943f5
commit
8db0dee5e0
1 file changed
+5
-2
+5
-2
@@ -948,14 +948,17 @@ end
|
||||
|
||||
--- Replaces characters that are invalid filenames.
|
||||
--
|
||||
-- Replaces the characters <code>\/:*?"<>|</code> with an <code>_</code>.
|
||||
-- Replaces the characters <code>\/:*?"<>|</code> with an <code>_</code>
|
||||
-- and removes trailing dots and spaces, in line with <https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions>.
|
||||
-- These characters are problematic on Windows filesystems. On Linux only
|
||||
-- <code>/</code> 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
|
||||
|
||||
|
||||
Reference in new issue
Block a user