Function linkcheck::validation::resolve_link[][src]

pub fn resolve_link(
    current_directory: &Path,
    link: &Path,
    options: &Options
) -> Result<PathBuf, Reason>
Expand description

Try to resolve a link relative to the current directory.

Note

The behaviour of this function may vary greatly depending on the Options passed in.

Root Directory

Setting a value for Options::root_directory() and Options::links_may_traverse_the_root_directory() act as a sort of sanity check to prevent links from going outside of a directory tree. They can also be useful in preventing directory traversal attacks and detecting brittle code (links that go outside of a specific directory may not exist on other machines).

When the link is absolute, it will be resolved relative to Options::root_directory(). If now root directory was provided, it will always trigger a Reason::TraversesParentDirectories error to prevent possible directory traversal attacks.

Default File

Because a link can only point to a file, when a link specifies a directory we’ll automatically append Options::default_file() to the end.

This will typically be something like "index.html", meaning a link to ./whatever/ will be resolved to ./whatever/index.html, which is the default behaviour for web browsers.

Alternate Extensions

Sometimes you might have a index.md document but also accept index.html as a valid link (like in mdbook). For this you can provide a mapping of Options::alternate_extensions() to fall back to when the original extension doesn’t work.