Skip to content

Commit

Permalink
fix: incorrect thrown exception when calling Path.GetFullPath with …
Browse files Browse the repository at this point in the history
…white-space (#1030)

Throw the correct `ArgumentException` instead of a `NullReferenceException` when calling Path.GetFullPath with a WhiteSpace string.
  • Loading branch information
vbreuss authored Aug 25, 2023
1 parent f0046b4 commit 00fb310
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override string GetFullPath(string path)
throw new ArgumentNullException(nameof(path), StringResources.Manager.GetString("VALUE_CANNOT_BE_NULL"));
}

if (path.Length == 0)
if (string.IsNullOrWhiteSpace(path))
{
throw CommonExceptions.PathIsNotOfALegalForm(nameof(path));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ public void GetFullPath_EmptyValue_ShouldThrowArgumentException()
Assert.Throws<ArgumentException>(action);
}

[Test]
public void GetFullPath_WithWhiteSpace_ShouldThrowArgumentException()
{
var mockFileSystem = new MockFileSystem();

TestDelegate action = () => mockFileSystem.Path.GetFullPath(" ");

Assert.Throws<ArgumentException>(action);
}

[Test]
public void GetFullPath_WithMultipleDirectorySeparators_ShouldReturnTheNormalizedForm()
{
Expand Down

0 comments on commit 00fb310

Please sign in to comment.