Skip to content

Commit

Permalink
fix: replace non-word chars in uploaded filenames
Browse files Browse the repository at this point in the history
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
  • Loading branch information
charislam committed May 22, 2024
1 parent 9ded715 commit 5036f2e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5036f2e

Please sign in to comment.