diff --git a/src/Testcontainers/Configurations/IOperatingSystem.cs b/src/Testcontainers/Configurations/IOperatingSystem.cs
index 5c99cda38..c67293c54 100644
--- a/src/Testcontainers/Configurations/IOperatingSystem.cs
+++ b/src/Testcontainers/Configurations/IOperatingSystem.cs
@@ -19,6 +19,6 @@ public interface IOperatingSystem
/// Path to normalize.
/// Normalized path.
[PublicAPI]
- string NormalizePath(string path);
+ string NormalizePath([CanBeNull] string path);
}
}
diff --git a/src/Testcontainers/Configurations/Images/ImageFromDockerfileConfiguration.cs b/src/Testcontainers/Configurations/Images/ImageFromDockerfileConfiguration.cs
index a1057deb2..5e4b6842f 100644
--- a/src/Testcontainers/Configurations/Images/ImageFromDockerfileConfiguration.cs
+++ b/src/Testcontainers/Configurations/Images/ImageFromDockerfileConfiguration.cs
@@ -6,6 +6,8 @@ namespace DotNet.Testcontainers.Configurations
///
internal sealed class ImageFromDockerfileConfiguration : DockerResourceConfiguration, IImageFromDockerfileConfiguration
{
+ private static readonly IOperatingSystem OS = new Unix();
+
///
/// Initializes a new instance of the class.
///
@@ -36,8 +38,8 @@ public ImageFromDockerfileConfiguration(
: base(dockerEndpointAuthenticationConfiguration, labels)
{
this.Image = image;
- this.Dockerfile = dockerfile;
- this.DockerfileDirectory = dockerfileDirectory;
+ this.Dockerfile = OS.NormalizePath(dockerfile);
+ this.DockerfileDirectory = OS.NormalizePath(dockerfileDirectory);
this.DeleteIfExists = deleteIfExists;
this.BuildArguments = buildArguments;
}
diff --git a/src/Testcontainers/Configurations/Unix.cs b/src/Testcontainers/Configurations/Unix.cs
index e34247b8b..59b083e7a 100644
--- a/src/Testcontainers/Configurations/Unix.cs
+++ b/src/Testcontainers/Configurations/Unix.cs
@@ -55,7 +55,7 @@ public Unix(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig)
///
public string NormalizePath(string path)
{
- return path.Replace('\\', '/');
+ return path?.Replace('\\', '/');
}
}
}
diff --git a/src/Testcontainers/Configurations/Windows.cs b/src/Testcontainers/Configurations/Windows.cs
index 0b58e636d..c280efe8b 100644
--- a/src/Testcontainers/Configurations/Windows.cs
+++ b/src/Testcontainers/Configurations/Windows.cs
@@ -55,7 +55,7 @@ public Windows(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConf
///
public string NormalizePath(string path)
{
- return path.Replace('/', '\\');
+ return path?.Replace('/', '\\');
}
}
}