Skip to content

Commit 6a1b82b

Browse files
committed
The Root property would crash on a relative path
1 parent 61815f8 commit 6a1b82b

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

Pathy.ApiVerificationTests/Pathy.ApiVerificationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</PackageReference>
1414
<PackageReference Include="PublicApiGenerator" Version="11.5.0" />
1515
<PackageReference Include="Verify.DiffPlex" Version="3.1.2" />
16-
<PackageReference Include="Verify.Xunit" Version="31.0.3" />
16+
<PackageReference Include="Verify.Xunit" Version="31.0.5" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

Pathy.Specs/ChainablePathSpecs.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ public void Can_get_the_root()
331331
path.Root.ToString().Should().Be(Path.GetPathRoot(path.ToString()));
332332
}
333333

334+
[Fact]
335+
public void Cannot_get_the_root_of_a_relative_path()
336+
{
337+
// Act
338+
var path = ChainablePath.From("temp/somefile.txt");
339+
340+
// Assert
341+
path.Root.ToString().Should().Be(ChainablePath.Null);
342+
}
343+
334344
[Theory]
335345
[InlineData("C:\\temp\\")]
336346
[InlineData("C:\\temp")]

Pathy.Specs/Pathy.Specs.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<ItemGroup>
2020
<PackageReference Include="xunit" Version="2.9.3" />
21-
<PackageReference Include="FluentAssertions" Version="8.7.1" />
21+
<PackageReference Include="FluentAssertions" Version="8.8.0" />
2222
<PackageReference Include="JetBrains.Annotations" Version="2025.2.2" />
2323
<PackageReference Include="coverlet.collector" Version="6.0.4" PrivateAssets="all">
2424
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

Pathy/ChainablePath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public string Extension
359359
/// <summary>
360360
/// Gets the root directory of the current path.
361361
/// </summary>
362-
public ChainablePath Root => From(Path.GetPathRoot(path));
362+
public ChainablePath Root => Path.IsPathRooted(path) ? From(Path.GetPathRoot(path)) : Null;
363363

364364
/// <summary>
365365
/// Gets a value indicating whether the path represented by the current object points to an existing file.

0 commit comments

Comments
 (0)