8000 Fix handling of non 7 bits reference names · mm201/libgit2sharp@aaa8c7e · GitHub
[go: up one dir, main page]

Skip to content

Commit aaa8c7e

Browse files
committed
Fix handling of non 7 bits reference names
1 parent ac34838 commit aaa8c7e

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
34
using LibGit2Sharp.Tests.TestHelpers;
45
using Xunit;
@@ -10,13 +11,14 @@ public class BranchFixture : BaseFixture
1011
{
1112
private readonly string[] expectedBranches = new[] { "br2", "master", "packed", "packed-test", "test", };
1213

13-
[Fact]
14-
public void CanCreateBranch()
14+
[Theory]
15+
[InlineData("unit_test")]
16+
[InlineData("Ångström")]
17+
public void CanCreateBranch(string name)
1518
{
1619
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
1720
using (var repo = new Repository(path.RepositoryPath))
1821
{
19-
const string name = "unit_test";
2022
Branch newBranch = repo.CreateBranch(name, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
2123
newBranch.ShouldNotBeNull();
2224
newBranch.Name.ShouldEqual(name);
@@ -247,6 +249,22 @@ public void CanLookupLocalBranch()
247249
}
248250
}
249251

252+
[Fact]
253+
public void CanLookupABranchWhichNameIsMadeOfNon7BitsAsciiCharacters()
254+
{
255+
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
256+
using (var repo = new Repository(path.RepositoryPath))
257+
{
258+
const string name = "Ångström";
259+
Branch newBranch = repo.CreateBranch(name, "be3563a");
260+
newBranch.ShouldNotBeNull();
261+
262+
Branch retrieved = repo.Branches["Ångström"];
263+
retrieved.ShouldNotBeNull();
< 107AA /td>
264+
retrieved.Tip.ShouldEqual(newBranch.Tip);
265+
}
266+
}
267+
250268
[Fact]
251269
public void LookingOutABranchByNameWithBadParamsThrows()
252270
{

LibGit2Sharp/Core/Libgit2UnsafeHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace LibGit2Sharp.Core
66
{
77
internal static unsafe class Libgit2UnsafeHelper
88
{
9+
private static readonly Utf8Marshaler marshaler = (Utf8Marshaler)Utf8Marshaler.GetInstance(string.Empty);
10+
911
public static IList<string> ListAllReferenceNames(RepositorySafeHandle repo, GitReferenceType types)
1012
{
1113
UnSafeNativeMethods.git_strarray strArray;
@@ -44,7 +46,7 @@ private static IList<string> BuildListOf(UnSafeNativeMethods.git_strarray strArr
4446
int numberOfEntries = gitStrArray->size.ToInt32();
4547
for (uint i = 0; i < numberOfEntries; i++)
4648
{
47-
var name = new string(gitStrArray->strings[i]);
49+
var name = (string)marshaler.MarshalNativeToManaged((IntPtr)gitStrArray->strings[i]);
4850
list.Add(name);
4951
}
5052

0 commit comments

Comments
 (0)
0