Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f723ca

Browse files
committed
Guard Repository.Ignore against invalid parameters
Fix libgit2#346
1 parent 3a7ec78 commit 7f723ca

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

LibGit2Sharp.Tests/IgnoreFixture.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Linq;
34
using LibGit2Sharp.Tests.TestHelpers;
45
using Xunit;
@@ -44,7 +45,26 @@ public void IsPathIgnoredShouldVerifyWhetherPathIsIgnored()
4445
repo.Ignore.ResetAllTemporaryRules();
4546

4647
Assert.False(repo.Ignore.IsPathIgnored("Foo.cs"));
47-
}
48+
}
49+
}
50+
51+
[Fact]
52+
public void CallingIsPathIgnoredWithBadParamsThrows()
53+
{
54+
using (var repo = new Repository(StandardTestRepoWorkingDirPath))
55+
{
56+
Assert.Throws<ArgumentException>(() => repo.Ignore.IsPathIgnored(string.Empty));
57+
Assert.Throws<ArgumentNullException>(() => repo.Ignore.IsPathIgnored(null));
58+
}
59+
}
60+
61+
[Fact]
62+
public void AddingATemporaryRuleWithBadParamsThrows()
63+
{
64+
using (var repo = new Repository(StandardTestRepoWorkingDirPath))
65+
{
66+
Assert.Throws<ArgumentNullException>(() => repo.Ignore.AddTemporaryRules(null));
67+
}
4868
}
4969
}
5070
}

LibGit2Sharp/Ignore.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ internal Ignore(Repository repo)
3131
/// <param name="rules">The content of a .gitignore file that will be applied.</param>
3232
public virtual void AddTemporaryRules(IEnumerable<string> rules)
3333
{
34+
Ensure.ArgumentNotNull(rules, "rules");
35+
3436
var allRules = rules.Aggregate(new StringBuilder(), (acc, x) =>
3537
{
3638
acc.Append(x);
@@ -59,6 +61,8 @@ public virtual void ResetAllTemporaryRules()
5961
/// <returns>true if the path should be ignored.</returns>
6062
public virtual bool IsPathIgnored(string relativePath)
6163
{
64+
Ensure.ArgumentNotNullOrEmptyString(relativePath, "relativePath");
65+
6266
return Proxy.git_ignore_path_is_ignored(repo.Handle, relativePath);
6367
}
6468
}

0 commit comments

Comments
 (0)