Skip to content

Commit 06a1248

Browse files
committed
fix: allow tree-parsing with entries whose paths has leading spaces work again
Related to gitbutlerapp/gitbutler#13198
1 parent 5b229c6 commit 06a1248

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

gix-object/src/tree/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl EntryMode {
111111
}
112112

113113
// Happy path: space is at index 6
114-
let space_pos = if i.get(6) == Some(&b' ') {
114+
let space_pos = if i.get(6) == Some(&b' ') && i.get(5) != Some(&b' ') {
115115
for b in i.iter().take(6) {
116116
let b = b.wrapping_sub(b'0') as u16;
117117
// Not a pure octal input.

gix-object/tests/object/tree/iter.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ fn everything() -> crate::Result {
7676
Ok(())
7777
}
7878

79+
#[test]
80+
fn leading_space_in_tree_name() -> crate::Result {
81+
let oid = hex_to_id("4d5fcadc293a348e88f777dc0920f11e7d71441c");
82+
let mut buf = b"40000 leading space\0".to_vec();
83+
buf.extend_from_slice(oid.as_bytes());
84+
85+
assert_eq!(
86+
TreeRefIter::from_bytes(&buf).collect::<Result<Vec<_>, _>>()?,
87+
vec![EntryRef {
88+
mode: tree::EntryKind::Tree.into(),
89+
filename: b" leading space".as_bstr(),
90+
oid: oid.as_ref(),
91+
}]
92+
);
93+
Ok(())
94+
}
95+
7996
mod lookup_entry {
8097
use gix_object::tree::EntryKind;
8198
use utils::entry;

0 commit comments

Comments
 (0)