normalizePath() removes a leading /

Mac & Linux style absolute paths become relative paths if passed to normalizePath():

alert(normalizePath("/users/username/folder/file.md"));

The result is: users/username/folder/file.md. So an absolute path has became a relative path, which might not work, depending on current directory.

For Windows normalizePath() works almost correctly if the path starts e.g. with C:\Users\. The only issue with this is that backslashes \ are replaced with forward slashes / (should this be discussed in another topic?).

Some Windows paths have the leading slash problem, too:

alert(normalizePath('\\\\network\\path'));

The result is: network/path instead of \\network\path.

Obsidian version: 0.12.15

normalizePath is for paths inside the vault. If you want to use absolute paths on desktop, you can use normalize from fs.

Thank you for the tip!

Two suggestions:

  • Add documentation to the API for normalizePath() that it’s only meant for relative paths in the vault, please.
  • Please fix directory separator characters on Windows.

What is the convention for feature request (or bug reports) concerning only the API? Should I create a topic in Feature requests category for improving the API documentation regarding normalizePath(), and another topic in Bug reports regarding the directory separator thing? Or is it just fine to post this kind of requests here in the API category?

Thanks! :slightly_smiling_face:

why don’t you make a pull request?