Skip to content

validation

Validation utilities.

Interface Description
ValidationMessageHolder Holds a validation message.
Function Description
getFileNameValidationMessage Validates a single file or folder name against every naming rule this module owns. The rules, checked in this order, and the first one broken names the message: 1. The name is not empty. 2. It holds no control character (U+0000 to U+001F). 3. It holds none of the characters getOsAndObsidianUnsafePathCharsRegExp matches. 4. It does not end with a dot or a space (hasWindowsTrailingChars). 5. It is not an MS-DOS device name (isWindowsReservedName), with or without an extension. Only rule 3 depends on the platform. Rules 2, 4 and 5 apply on every platform, because a vault is synced, and a name created on macOS or Linux that Windows refuses breaks the vault there. The character set follows the platform because it is Obsidian’s own refusal set, which differs per platform: a name such as a?b is accepted on macOS, where Obsidian creates it.
getOsAndObsidianUnsafePathCharsRegExp Returns a regexp matching all unsafe characters in file names/paths. Includes both the platform’s refused characters (getOsUnsafePathCharsRegExp) and the ones that break links (OBSIDIAN_UNSAFE_FILENAME_CHARS).
getOsUnsafePathCharsRegExp Returns a regexp matching the characters Obsidian refuses in a file name on the given platform. That is WINDOWS_UNSAFE_PATH_CHARS on Windows, ANDROID_UNSAFE_PATH_CHARS on Android and UNIX_UNSAFE_PATH_CHARS everywhere else. It is Obsidian’s set rather than the file system’s, so a name it accepts can be created through the vault.
getPathValidationMessage Validates every segment of a vault path with getFileNameValidationMessage.
hasWindowsTrailingChars Checks 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.
isValidationMessageHolder Type guard to check if a value is a validation message holder.
isWindowsReservedName Checks 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.
trimWindowsTrailingChars Removes 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.
Variable Description
ANDROID_UNSAFE_PATH_CHARS The characters Obsidian refuses in a file name on Android, plus the NUL no file system stores. Obsidian adds * ? < > " to the UNIX_UNSAFE_PATH_CHARS set there, because Android’s shared storage refuses them. Read from Obsidian 1.15.0’s app.js.
OBSIDIAN_UNSAFE_FILENAME_CHARS Matches characters that are not safe to use in file names within Obsidian.
UNIX_UNSAFE_PATH_CHARS The characters Obsidian refuses in a file name on macOS, Linux and iOS, plus the NUL no file system stores. This is Obsidian’s refusal set, not the file system’s: macOS and Linux store \ and :, but Obsidian refuses both, so a name holding either cannot be created through the vault there. Read from Obsidian 1.15.0’s app.js.
WINDOWS_UNSAFE_PATH_CHARS The characters Obsidian refuses in a file name on Windows. Read from Obsidian 1.15.0’s app.js, whose name check throws on this set from app.vault.create, a rename and Sync alike.