From 5036f2e2297261fcffc92fc3f599063b72be579e Mon Sep 17 00:00:00 2001 From: Charis Lam <26616127+charislam@users.noreply.github.com> Date: Fri, 10 May 2024 17:03:52 -0400 Subject: [PATCH] fix: replace non-word chars in uploaded filenames Storage maintains a list of allowed characters, which excludes some characters used automatically by OSes for naming files (e.g., Mac default screenshot naming). To preempt errors, replace any characters that aren't alphanumerics, underscores, hyphens, or periods with underscores. See: https://forum.obsidian.md/t/unable-to-attach-screenshot-images-in-macos-14-0-when-wikilinks-turned-off-urlencode-u-202f-char/68410/6 --- .../localStores/storageExplorer/StorageExplorerStore.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx b/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx index 1c099791c4e58..8b0e9bce892d3 100644 --- a/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx +++ b/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx @@ -561,7 +561,14 @@ class StorageExplorerStore { const fileName = !isWithinFolder ? this.sanitizeNameForDuplicateInColumn(file.name, autofix) : file.name - const formattedFileName = has(file, ['path']) && isWithinFolder ? file.path : fileName + const unsanitizedFormattedFileName = + has(file, ['path']) && isWithinFolder ? file.path : fileName + /** + * MacOS 14.0+ uses a narrow no-break space (U+202F) in the timestamp of + * automatically named screenshots (12-hour clock only). That is not a + * valid filename character for storage, so replace with a normal space. + */ + const formattedFileName = unsanitizedFormattedFileName.replace(/\u202F/g, ' ') const formattedPathToFile = pathToFile.length > 0 ? `${pathToFile}/${formattedFileName}` : formattedFileName