Skip to content

Commit

Permalink
fix(errors): handle out of bounds access in PathList display (#313)
Browse files Browse the repository at this point in the history
Fixes #309

---------

Signed-off-by: simonsan <[email protected]>
Co-authored-by: Alexander Weiss <[email protected]>
  • Loading branch information
simonsan and aawsome authored Oct 6, 2024
1 parent f68ffa3 commit be4f18f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions crates/core/src/repofile/snapshotfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,13 +1193,11 @@ pub struct PathList(Vec<PathBuf>);

impl Display for PathList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if !self.0.is_empty() {
write!(f, "{:?}", self.0[0])?;
}
for p in &self.0[1..] {
write!(f, ",{p:?}")?;
}
Ok(())
self.0
.iter()
.map(|p| p.to_string_lossy())
.format(",")
.fmt(f)
}
}

Expand Down Expand Up @@ -1368,4 +1366,14 @@ mod tests {
assert_eq!(crit.paths, is_path);
assert_eq!(crit.tags, is_tags);
}

#[rstest]
#[case(vec![], "")]
#[case(vec!["test"], "test")]
#[case(vec!["test", "test", "test"], "test,test,test")]
fn test_display_path_list_passes(#[case] input: Vec<&str>, #[case] expected: &str) {
let path_list = PathList::from_iter(input);
let result = path_list.to_string();
assert_eq!(expected, &result);
}
}

0 comments on commit be4f18f

Please sign in to comment.