Skip to content

Commit e6313c4

Browse files
committed
Simplify TrimTrailingDirectorySeparator
1 parent c31d913 commit e6313c4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Source/Testably.Abstractions.Testing/Helpers/PathHelper.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,12 @@ internal static string TrimOnWindows(this string path, MockFileSystem fileSystem
178178
internal static string TrimTrailingDirectorySeparator(this string path,
179179
MockFileSystem fileSystem)
180180
{
181-
path = path.TrimEnd(fileSystem.Path.DirectorySeparatorChar);
182-
if (string.IsNullOrEmpty(path))
181+
if (path.Length == 1 && path[0] == fileSystem.Path.DirectorySeparatorChar)
183182
{
184-
return $"{fileSystem.Path.DirectorySeparatorChar}";
183+
return path;
185184
}
186185

187-
return path;
186+
return path.TrimEnd(fileSystem.Path.DirectorySeparatorChar);
188187
}
189188

190189
private static void CheckPathArgument(Execute execute, [NotNull] string? path, string paramName,

0 commit comments

Comments
 (0)