Skip to content

Commit

Permalink
fix paths in config are not validated when they don't start with ~
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jun 11, 2024
1 parent afcb3d7 commit e39d431
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions v2/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,17 @@ fn resolve_path<'de, D: Deserializer<'de>>(
if &s == "null" {
return Ok(None);
}
if !s.starts_with(PREFIX) {
return Ok(Some(PathBuf::from(s)));
}

let Some(mut path) = dirs::home_dir() else {
return Ok(None);
let path = if let Some(rel) = s.strip_prefix(PREFIX) {
let Some(mut home) = dirs::home_dir() else {
return Ok(None);
};
home.push(rel);
home
} else {
PathBuf::from(s)
};

path.push(&s[2..]);
if !path.is_dir() {
log::error!("Path {:?} in config is not a directory", path);
return Ok(None);
Expand Down Expand Up @@ -296,7 +298,9 @@ impl UserConfig {
}
}

log::debug!("config.yml nor config.yaml was found in {path:?}. Using the default config");
log::debug!(
"Neither config.yml nor config.yaml was found in {path:?}. Using the default config"
);
Ok(Self::default())
}

Expand Down

0 comments on commit e39d431

Please sign in to comment.