From a4d5b6b4d081fadfe933e49bd4d71d8c91ffa06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Tue, 16 Apr 2024 13:45:12 +0200 Subject: [PATCH] builder/normalizeWorkdir: Always return cleaned path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `normalizeWorkdir` function has two branches, one that returns a result of `filepath.Join` which always returns a cleaned path, and another one where the input string is returned unmodified. To make these two outputs consistent, also clean the path in the second branch. This also makes the cleaning of the container workdir explicit in the `normalizeWorkdir` function instead of relying on the `SetupWorkingDirectory` to mutate it. Signed-off-by: Paweł Gronowski --- builder/dockerfile/dispatchers_unix.go | 2 +- integration-cli/docker_cli_build_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/dockerfile/dispatchers_unix.go b/builder/dockerfile/dispatchers_unix.go index ba8e1d90531c0..d69e184220dac 100644 --- a/builder/dockerfile/dispatchers_unix.go +++ b/builder/dockerfile/dispatchers_unix.go @@ -22,7 +22,7 @@ func normalizeWorkdir(_ string, current string, requested string) (string, error if !filepath.IsAbs(requested) { return filepath.Join(string(os.PathSeparator), current, requested), nil } - return requested, nil + return filepath.Clean(requested), nil } // resolveCmdLine takes a command line arg set and optionally prepends a platform-specific diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 858d496b40715..05f9e4b8af130 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -4296,7 +4296,7 @@ func (s *DockerCLIBuildSuite) TestBuildBuildTimeArgExpansion(c *testing.T) { imgName := "bldvarstest" wdVar := "WDIR" - wdVal := "/tmp/" + wdVal := "/tmp" addVar := "AFILE" addVal := "addFile" copyVar := "CFILE"