Skip to content

Commit

Permalink
fix: join_bstr_unix_pathsep() works more suitably if base path is e…
Browse files Browse the repository at this point in the history
…mpty.
  • Loading branch information
Byron committed Apr 25, 2023
1 parent 27a39ca commit bd1ae0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gix-path/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn into_bstr<'a>(path: impl Into<Cow<'a, Path>>) -> Cow<'a, BStr> {
/// Join `path` to `base` such that they are separated with a `/`, i.e. `base/path`.
pub fn join_bstr_unix_pathsep<'a, 'b>(base: impl Into<Cow<'a, BStr>>, path: impl Into<&'b BStr>) -> Cow<'a, BStr> {
let mut base = base.into();
if base.last() != Some(&b'/') {
if !base.is_empty() && base.last() != Some(&b'/') {
base.to_mut().push(b'/');
}
base.to_mut().extend_from_slice(path.into());
Expand Down
8 changes: 4 additions & 4 deletions gix-path/tests/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ mod join_bstr_unix_pathsep {
assert_eq!(join_bstr_unix_pathsep(b("base/"), ""), b("base/"));
}
#[test]
fn empty_base_creates_absolute_paths() {
assert_eq!(join_bstr_unix_pathsep(b(""), ""), b("/"));
assert_eq!(join_bstr_unix_pathsep(b(""), "hi"), b("/hi"));
assert_eq!(join_bstr_unix_pathsep(b(""), "/hi"), b("//hi"));
fn empty_base_leaves_everything_untouched() {
assert_eq!(join_bstr_unix_pathsep(b(""), ""), b(""));
assert_eq!(join_bstr_unix_pathsep(b(""), "hi"), b("hi"));
assert_eq!(join_bstr_unix_pathsep(b(""), "/hi"), b("/hi"));
}
}

0 comments on commit bd1ae0d

Please sign in to comment.