Skip to content

Commit e4e6269

Browse files
committed
fix(config): normalize included config paths
Without normalizing included config paths, `Definition::root()` will do `parent().parent()` on non-normalized paths containing `..` segments. And that will remove `..` and result in wrong path resolution.
1 parent c14ccdf commit e4e6269

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/cargo/util/context/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,7 @@ impl ConfigInclude {
23472347
Definition::Environment(_) | Definition::Cli(None) | Definition::BuiltIn => gctx.cwd(),
23482348
}
23492349
.join(&self.path);
2350+
let abs_path = paths::normalize_path(&abs_path);
23502351

23512352
if self.optional && !abs_path.exists() {
23522353
tracing::info!(

tests/testsuite/config_include.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ fn env_relative_path_included_from_same_level() {
617617
);
618618
assert_e2e().eq(
619619
env.get("OUTER").unwrap().to_str().unwrap(),
620-
str!["[ROOT]/foo/.cargo/../../outer-val"],
620+
str!["[ROOT]/outer-val"],
621621
);
622622
}
623623

@@ -642,6 +642,6 @@ fn env_relative_path_included_from_upper_level() {
642642

643643
assert_e2e().eq(
644644
env.get("MY_ENV").unwrap().to_str().unwrap(),
645-
str!["[ROOT]/outer/foo/.cargo/../val"],
645+
str!["[ROOT]/val"],
646646
);
647647
}

0 commit comments

Comments
 (0)