Skip to content

obsidian/validation

Validation utilities.

InterfaceDescription
ValidationMessageHolderHolds a validation message.
FunctionDescription
getOsAndObsidianUnsafePathCharsRegExpReturns a regexp matching all unsafe characters in file names/paths. Includes both OS-specific restrictions and Obsidian-specific ones.
getOsUnsafePathCharsRegExpReturns a regexp matching characters that are not safe to use in file names/paths at the OS level.
hasWindowsTrailingCharsChecks whether a name ends with the dots or spaces Windows refuses. Answers for Windows regardless of the platform in use: a vault is synced, so the rules that matter are not necessarily those of the machine asking.
isValidationMessageHolderType guard to check if a value is a validation message holder.
isWindowsReservedNameChecks whether a name is one of the MS-DOS device names Windows refuses. Two steps the caller would otherwise have to know about happen here: trailing dots and spaces are trimmed BEFORE the test, because Windows strips them before deciding and CON is therefore as reserved as CON; and the extension is dropped, because CON.md is reserved too. CONIN$ / CONOUT$ and the superscript COM² forms are deliberately NOT reserved: they are accepted by every Windows version that runs Obsidian, and matching them would rename files that work. Answers for Windows regardless of the platform in use: a vault is synced, so the rules that matter are not necessarily those of the machine asking.
trimWindowsTrailingCharsRemoves the trailing dots and spaces Windows refuses from the end of a name. Trim before testing for a reserved name, never after: trimming afterwards turns an accepted CON into a rejected CON. isWindowsReservedName already does this internally.
VariableDescription
OBSIDIAN_UNSAFE_FILENAME_CHARSMatches characters that are not safe to use in file names within Obsidian.
UNIX_UNSAFE_PATH_CHARSUnix-specific unsafe file name path characters.
WINDOWS_UNSAFE_PATH_CHARSWindows-specific unsafe file name path characters.