Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit a4fe02d

Browse files
authored
Merge pull request #1374 from github/fixes/1240-nullref-diffservice
Avoid possible NRE in DiffService.
2 parents 75ec005 + 89748d2 commit a4fe02d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/GitHub.Exports/Models/DiffUtilities.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public static class DiffUtilities
1313

1414
public static IEnumerable<DiffChunk> ParseFragment(string diff)
1515
{
16+
Guard.ArgumentNotNull(diff, nameof(diff));
17+
1618
var reader = new LineReader(diff);
1719
string line;
1820
DiffChunk chunk = null;

src/GitHub.InlineReviews/Services/DiffService.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ public async Task<IReadOnlyList<DiffChunk>> Diff(
3232
string path)
3333
{
3434
var patch = await gitClient.Compare(repo, baseSha, headSha, path);
35-
return DiffUtilities.ParseFragment(patch).ToList();
35+
36+
if (patch != null)
37+
{
38+
return DiffUtilities.ParseFragment(patch).ToList();
39+
}
40+
else
41+
{
42+
return new DiffChunk[0];
43+
}
3644
}
3745

3846
/// <inheritdoc/>
@@ -44,7 +52,15 @@ public async Task<IReadOnlyList<DiffChunk>> Diff(
4452
byte[] contents)
4553
{
4654
var changes = await gitClient.CompareWith(repo, baseSha, headSha, path, contents);
47-
return DiffUtilities.ParseFragment(changes.Patch).ToList();
55+
56+
if (changes?.Patch != null)
57+
{
58+
return DiffUtilities.ParseFragment(changes.Patch).ToList();
59+
}
60+
else
61+
{
62+
return new DiffChunk[0];
63+
}
4864
}
4965
}
5066
}

0 commit comments

Comments
 (0)