Skip to content

Commit 00fb310

Browse files
authored
fix: incorrect thrown exception when calling Path.GetFullPath with white-space (#1030)
Throw the correct `ArgumentException` instead of a `NullReferenceException` when calling Path.GetFullPath with a WhiteSpace string.
1 parent f0046b4 commit 00fb310

File tree

2 files changed

+11
-1
lines changed
  • src/TestableIO.System.IO.Abstractions.TestingHelpers
  • tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests

2 files changed

+11
-1
lines changed

src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override string GetFullPath(string path)
3939
throw new ArgumentNullException(nameof(path), StringResources.Manager.GetString("VALUE_CANNOT_BE_NULL"));
4040
}
4141

42-
if (path.Length == 0)
42+
if (string.IsNullOrWhiteSpace(path))
4343
{
4444
throw CommonExceptions.PathIsNotOfALegalForm(nameof(path));
4545
}

tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ public void GetFullPath_EmptyValue_ShouldThrowArgumentException()
266266
Assert.Throws<ArgumentException>(action);
267267
}
268268

269+
[Test]
270+
public void GetFullPath_WithWhiteSpace_ShouldThrowArgumentException()
271+
{
272+
var mockFileSystem = new MockFileSystem();
273+
274+
TestDelegate action = () => mockFileSystem.Path.GetFullPath(" ");
275+
276+
Assert.Throws<ArgumentException>(action);
277+
}
278+
269279
[Test]
270280
public void GetFullPath_WithMultipleDirectorySeparators_ShouldReturnTheNormalizedForm()
271281
{

0 commit comments

Comments
 (0)