fix(ui): UnifiedDiffParser handles paths with spaces and git-quoted paths

# Conflicts:
#	docs/open.md
This commit is contained in:
mika kuns
2026-07-23 20:07:53 +02:00
3 changed files with 206 additions and 10 deletions
@@ -106,4 +106,72 @@ public class UnifiedDiffParserTests
Assert.False(file.HasLines);
Assert.True(file.IsEmptyContent);
}
[Fact]
public void Path_with_spaces_is_parsed_in_full()
{
const string raw =
"diff --git a/pfad mit space.txt b/pfad mit space.txt\n" +
"index 111..222 100644\n" +
"--- a/pfad mit space.txt\t\n" +
"+++ b/pfad mit space.txt\t\n" +
"@@ -1,1 +1,1 @@\n" +
"-old\n" +
"+new\n";
var file = Assert.Single(UnifiedDiffParser.Parse(raw));
Assert.Equal("pfad mit space.txt", file.Path);
Assert.Equal(DiffFileStatus.Modified, file.Status);
}
[Fact]
public void Rename_with_spaces_on_both_sides_captures_full_paths()
{
const string raw =
"diff --git a/old name with space.txt b/new name with space.txt\n" +
"similarity index 75%\n" +
"rename from old name with space.txt\n" +
"rename to new name with space.txt\n" +
"index 111..222 100644\n" +
"--- a/old name with space.txt\t\n" +
"+++ b/new name with space.txt\t\n";
var file = Assert.Single(UnifiedDiffParser.Parse(raw));
Assert.Equal(DiffFileStatus.Renamed, file.Status);
Assert.Equal("old name with space.txt", file.OldPath);
Assert.Equal("new name with space.txt", file.Path);
}
[Fact]
public void Git_quoted_unicode_path_is_unquoted()
{
// git quotes paths containing non-ASCII bytes as C-style octal escapes,
// e.g. "pfad_ä.txt" -> "pfad_\303\244.txt" (UTF-8 bytes for 'ä').
const string raw =
"diff --git \"a/pfad_\\303\\244.txt\" \"b/pfad_\\303\\244.txt\"\n" +
"index 111..222 100644\n" +
"--- \"a/pfad_\\303\\244.txt\"\n" +
"+++ \"b/pfad_\\303\\244.txt\"\n" +
"@@ -1,1 +1,1 @@\n" +
"-old\n" +
"+new\n";
var file = Assert.Single(UnifiedDiffParser.Parse(raw));
Assert.Equal("pfad_ä.txt", file.Path);
}
[Fact]
public void Binary_file_with_spaces_is_parsed_in_full()
{
const string raw =
"diff --git a/bin file.png b/bin file.png\n" +
"new file mode 100644\n" +
"index 000..abc\n" +
"Binary files /dev/null and b/bin file.png differ\n";
var file = Assert.Single(UnifiedDiffParser.Parse(raw));
Assert.Equal("bin file.png", file.Path);
Assert.True(file.IsBinary);
Assert.False(file.HasLines);
}
}