diff --git a/README.md b/README.md index 256be0c698..5f0da195d8 100644 --- a/README.md +++ b/README.md @@ -481,7 +481,7 @@ Options: Base URL or website root directory to check relative URLs e.g. or `/path/to/public` --root-path - Root path to use when checking absolute local links, base option is ignored when this is set + Root path to use when checking absolute local links --basic-auth Basic authentication support. E.g. `http://example.com username:password` diff --git a/lychee-lib/src/utils/path.rs b/lychee-lib/src/utils/path.rs index 275b0173d8..ca295ce6a3 100644 --- a/lychee-lib/src/utils/path.rs +++ b/lychee-lib/src/utils/path.rs @@ -59,19 +59,27 @@ pub(crate) fn resolve( Some(root) => &join(root.to_path_buf(), absolute), None => absolute, }; - // Absolute local links (leading slash) require the `base_url` to - // define the document root. Silently ignore the link in case the - // `base_url` is not defined. - let Some(base) = get_base_dir(base) else { - return Ok(None); - }; - let Some(dir) = dirname(&base) else { - return Err(ErrorKind::InvalidBase( - base.display().to_string(), - "The given directory cannot be a base".to_string(), - )); - }; - join(dir.to_path_buf(), with_root_path) + match get_base_dir(base) { + Some(base) => { + let Some(dir) = dirname(&base) else { + return Err(ErrorKind::InvalidBase( + base.display().to_string(), + "The given directory cannot be a base".to_string(), + )); + }; + join(dir.to_path_buf(), with_root_path) + } + None => { + if root_path.is_some() { + with_root_path.to_path_buf() + } else { + // Absolute local links (leading slash) require the `base_url` to + // define the document root. Silently ignore the link in case the + // `base_url` is not defined. + return Ok(None); + } + } + } } _ => return Err(ErrorKind::InvalidFile(dst.to_path_buf())), };