Skip to content

Commit

Permalink
Fix dependency root bug affecting Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed May 10, 2023
1 parent 95b4bbc commit 49e0353
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cargo-dylint/tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ libraries = [
predicate::str::is_match(r#"Could not canonicalize "[^"]*""#)
.unwrap()
.or(predicate::str::is_match(
r#"Pattern `[^`]*` refers to paths outside of `[^`]*`"#,
r#"Pattern `[^`]*` could refer to `[^`]*`, which is outside of `[^`]*`"#,
)
.unwrap()),
);
Expand Down
10 changes: 9 additions & 1 deletion dylint/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ fn library_package(
) -> Result<Vec<Package>> {
let dep = dependency(opts, metadata, config, library)?;

// smoelius: The dependency root cannot be canonicalized here. It could contain a `glob` pattern
// (e.g., `*`), because Dylint allows `path` entries to contain `glob` patterns.
let dependency_root = dependency_root(config, &dep)?;

let pattern = if let Some(pattern) = &library.pattern {
Expand All @@ -189,9 +191,15 @@ fn library_package(
let path_buf = path
.canonicalize()
.with_context(|| format!("Could not canonicalize {path:?}"))?;
// smoelius: On Windows, the dependency root must be canonicalized to ensure it
// has a path prefix.
let dependency_root = dependency_root
.canonicalize()
.with_context(|| format!("Could not canonicalize {dependency_root:?}"))?;
ensure!(
path_buf.starts_with(&dependency_root),
"Pattern `{pattern}` refers to paths outside of `{}`",
"Pattern `{pattern}` could refer to `{}`, which is outside of `{}`",
path_buf.to_string_lossy(),
dependency_root.to_string_lossy()
);
}
Expand Down

0 comments on commit 49e0353

Please sign in to comment.