From e312143de98aff4c4ac2c795166d86de5fbb3d8f Mon Sep 17 00:00:00 2001
From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com>
Date: Wed, 2 Nov 2022 12:16:59 +0100
Subject: [PATCH] refactor: Always normalize paths to forward slashes for the
Docker container image build
---
src/Testcontainers/Configurations/IOperatingSystem.cs | 2 +-
.../Images/ImageFromDockerfileConfiguration.cs | 6 ++++--
src/Testcontainers/Configurations/Unix.cs | 2 +-
src/Testcontainers/Configurations/Windows.cs | 2 +-
4 files changed, 7 insertions(+), 5 deletions(-)
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('/', '\\');
}
}
}