Skip to content

Commit

Permalink
refactor: Always normalize paths to forward slashes for the Docker co…
Browse files Browse the repository at this point in the history
…ntainer image build
  • Loading branch information
HofmeisterAn committed Nov 2, 2022
1 parent d4a1e71 commit e312143
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Testcontainers/Configurations/IOperatingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public interface IOperatingSystem
/// <param name="path">Path to normalize.</param>
/// <returns>Normalized path.</returns>
[PublicAPI]
string NormalizePath(string path);
string NormalizePath([CanBeNull] string path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace DotNet.Testcontainers.Configurations
/// <inheritdoc cref="IImageFromDockerfileConfiguration" />
internal sealed class ImageFromDockerfileConfiguration : DockerResourceConfiguration, IImageFromDockerfileConfiguration
{
private static readonly IOperatingSystem OS = new Unix();

/// <summary>
/// Initializes a new instance of the <see cref="ImageFromDockerfileConfiguration" /> class.
/// </summary>
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers/Configurations/Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Unix(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig)
/// <inheritdoc />
public string NormalizePath(string path)
{
return path.Replace('\\', '/');
return path?.Replace('\\', '/');
}
}
}
2 changes: 1 addition & 1 deletion src/Testcontainers/Configurations/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Windows(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConf
/// <inheritdoc />
public string NormalizePath(string path)
{
return path.Replace('/', '\\');
return path?.Replace('/', '\\');
}
}
}

0 comments on commit e312143

Please sign in to comment.