Skip to content

Commit

Permalink
rust: Reject empty name
Browse files Browse the repository at this point in the history
Corresponding to the C change.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Aug 19, 2024
1 parent b6fd6ec commit 81f1d1b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rust/composefs/src/dumpfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ fn unescape_to_osstr(s: &str) -> Result<Cow<OsStr>> {
/// Unescape a string into a Rust `Path` which is really just an alias for a byte array,
/// although there is an implicit assumption that there are no embedded `NUL` bytes.
fn unescape_to_path(s: &str) -> Result<Cow<Path>> {
let r = match unescape_to_osstr(s)? {
let v = unescape_to_osstr(s).and_then(|v| {
if v.is_empty() {
anyhow::bail!("Invalid empty path");
}
Ok(v)
})?;
let r = match v {
Cow::Borrowed(v) => Cow::Borrowed(Path::new(v)),
Cow::Owned(v) => Cow::Owned(PathBuf::from(v)),
};
Expand Down Expand Up @@ -433,6 +439,11 @@ mod tests {
}
}

#[test]
fn test_unescape_path() {
assert!(unescape_to_path("").is_err());
}

#[test]
fn test_parse() {
const CONTENT: &str = include_str!("../../../tests/assets/special.dump");
Expand Down

0 comments on commit 81f1d1b

Please sign in to comment.