Skip to content

Commit

Permalink
fix: replace non-word chars in uploaded filenames (#26022)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
charislam committed May 22, 2024
1 parent 9ded715 commit 69c1988
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
/**
* Storage maintains a list of allowed characters, which excludes
* characters such as the narrow no-break space used in Mac screenshots.
* To preempt errors, replace all non-word characters with underscores.
*/
const formattedFileName = unsanitizedFormattedFileName.replace(/[^\w.-]/g, '_')
const formattedPathToFile =
pathToFile.length > 0 ? `${pathToFile}/${formattedFileName}` : formattedFileName

Expand Down

0 comments on commit 69c1988

Please sign in to comment.