Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(errors): handle out of bounds access in PathList display #313

Merged
merged 3 commits into from
Oct 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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())

Check warning on line 1198 in crates/core/src/repofile/snapshotfile.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repofile/snapshotfile.rs#L1198

Added line #L1198 was not covered by tests
.format(",")
.fmt(f)
}
}

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

#[rstest]
#[case(vec![], "")]
aawsome marked this conversation as resolved.
Show resolved Hide resolved
#[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);
}
}