Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,15 @@ public bool HasExtension(ReadOnlySpan<char> path)

/// <inheritdoc cref="IPath.HasExtension(string)" />
public bool HasExtension([NotNullWhen(true)] string? path)
=> System.IO.Path.HasExtension(path);
{
if (path == null)
{
return false;
}

return TryGetExtensionIndex(path, out var dotIndex)
&& dotIndex < path.Length - 1;
}

#if FEATURE_SPAN
/// <inheritdoc cref="IPath.IsPathFullyQualified(ReadOnlySpan{char})" />
Expand Down Expand Up @@ -406,7 +414,11 @@ public ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path)
#if FEATURE_PATH_ADVANCED
/// <inheritdoc cref="IPath.TrimEndingDirectorySeparator(string)" />
public string TrimEndingDirectorySeparator(string path)
=> System.IO.Path.TrimEndingDirectorySeparator(path);
{
return EndsInDirectorySeparator(path) && path.Length != GetRootLength(path)
? path.Substring(0, path.Length - 1)
: path;
}
#endif

#if FEATURE_PATH_JOIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,11 @@ private bool IncludeSimulatedTests(ClassModel @class)
"GetPathRootTests",
"GetRandomFileNameTests",
"GetTempPathTests",
"HasExtensionTests",
"IsPathRootedTests",
"JoinTests",
"Tests",
"TrimEndingDirectorySeparatorTests",
"TryJoinTests"
];
return @class.Namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void HasExtension_Null_ShouldReturnFalse()
}

[SkippableTheory]
[InlineAutoData("abc.", false)]
[InlineAutoData(".foo", true)]
[InlineAutoData(".abc.xyz", true)]
[InlineAutoData("foo", false)]
Expand All @@ -30,6 +31,7 @@ public void HasExtension_ShouldReturnExpectedResult(

#if FEATURE_SPAN
[SkippableTheory]
[InlineAutoData("abc.", false)]
[InlineAutoData(".foo", true)]
[InlineAutoData(".abc.xyz", true)]
[InlineAutoData("foo", false)]
Expand Down