Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Dec 1, 2024
1 parent 2ef01d8 commit d848c43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ Options:
Base URL or website root directory to check relative URLs e.g. <https://example.com> or `/path/to/public`
--root-path <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_AUTH>
Basic authentication support. E.g. `http://example.com username:password`
Expand Down
34 changes: 21 additions & 13 deletions lychee-lib/src/utils/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
};
Expand Down

0 comments on commit d848c43

Please sign in to comment.