Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves null reference exception in Path.Equals #802

Merged
merged 2 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/Core/Abstractions.Tests/PathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,47 @@ public void Path_ToCollection()
// assert
result.MatchSnapshot();
}

[Fact]
public void Path_Equals_Null()
{
// arrange
Path hero = Path.New("hero");
Path friends = null;

// act
var areEqual = hero.Equals(friends);

// assert
Assert.False(areEqual);
}

[Fact]
public void Path_Equals_False()
{
// arrange
Path hero = Path.New("hero");
Path friends = Path.New("hero").Append("friends");

// act
var areEqual = hero.Equals(friends);

// assert
Assert.False(areEqual);
}

[Fact]
public void Path_Equals_True()
{
// arrange
Path friends1 = Path.New("hero").Append("friends");
Path friends2 = Path.New("hero").Append("friends");

// act
var areEqual = friends1.Equals(friends2);

// assert
Assert.True(areEqual);
}
}
}
9 changes: 7 additions & 2 deletions src/Core/Abstractions/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ public bool Equals(Path other)
return true;
}

return (other.Parent.Equals(Parent)
if (ReferenceEquals(null, other))
{
return false;
}

return ((Parent == null && other.Parent == null) || other.Parent.Equals(Parent))
&& string.Equals(other.Name, Name, StringComparison.Ordinal)
&& other.Index.Equals(Index));
&& other.Index.Equals(Index);
}

public override bool Equals(object obj)
Expand Down