mvavassori / obsidian-web-clipper

Obsidian Web Clipper is a simple Browser extension for Obsidian, a popular note-taking application. With this extension, you can quickly capture notes directly from your web browser and save them to your Obsidian vaults.
MIT License
84 stars 9 forks source link

folderStructure RegEx rejects allowed Obsidian folder names #1

Closed latesc closed 1 year ago

latesc commented 1 year ago

Problem

The current folderPattern RegEx does not allow for folder names that Obsidian allows, as well as subdirectories in the folder structure. This prevents users from saving clips effectively. The invalid character alert also prompts that using / is invalid, which doesn't match the pattern.

Directories that folderPattern currently does not allow:

subdirectory/subdirectory2/{title}
sub.directory/{title}
sub.directory/subdirectory2/{title}
subdirectory/sub(directory)/{title}

Proposed Solution

Changing the regex to allow all characters except the ones that are disallowed

/^((\{title\}|[^\x5C\x3A\x2A\x3F\x22\x3C\x3E\x7C]+)\/)*\{title\}$/
mvavassori commented 1 year ago

The proposed solution has a problem with double "/" characters, for example the folder path Folder//{title} would still pass the test. I'm pondering using this solution: const folderPattern = /^([\w\s().]+\/)*\{title\}$/;

latesc commented 1 year ago

That is true, and your solution looks good to me. Appreciate what you're doing with this extension!