Skip to content

Commit c9e04a2

Browse files
fix: improved path normalization in mock file stream for relative paths
1 parent 4e724f5 commit c9e04a2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public MockFileStream(
5555
ThrowIfInvalidModeAccess(mode, access);
5656

5757
this.mockFileDataAccessor = mockFileDataAccessor ?? throw new ArgumentNullException(nameof(mockFileDataAccessor));
58-
path = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).TrimSlashes();
58+
path = NormalizePath(path);
5959
this.path = path;
6060
this.options = options;
6161

@@ -360,4 +360,15 @@ private TimeAdjustments GetTimeAdjustmentsForFileStreamWhenFileExists(FileMode m
360360
return TimeAdjustments.None;
361361
}
362362
}
363+
364+
private string NormalizePath(string path)
365+
{
366+
var normalizedPath = path
367+
.Replace(
368+
mockFileDataAccessor.Path.AltDirectorySeparatorChar,
369+
mockFileDataAccessor.Path.DirectorySeparatorChar)
370+
.TrimSlashes();
371+
normalizedPath = mockFileDataAccessor.Path.GetFullPath(normalizedPath);
372+
return normalizedPath;
373+
}
363374
}

0 commit comments

Comments
 (0)