Browse code

builder/normalizeWorkdir: Always return cleaned path

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 <pawel.gronowski@docker.com>

Paweł Gronowski authored on 2024/04/16 20:45:12
Showing 2 changed files
... ...
@@ -22,7 +22,7 @@ func normalizeWorkdir(_ string, current string, requested string) (string, error
22 22
 	if !filepath.IsAbs(requested) {
23 23
 		return filepath.Join(string(os.PathSeparator), current, requested), nil
24 24
 	}
25
-	return requested, nil
25
+	return filepath.Clean(requested), nil
26 26
 }
27 27
 
28 28
 // resolveCmdLine takes a command line arg set and optionally prepends a platform-specific
... ...
@@ -4296,7 +4296,7 @@ func (s *DockerCLIBuildSuite) TestBuildBuildTimeArgExpansion(c *testing.T) {
4296 4296
 	imgName := "bldvarstest"
4297 4297
 
4298 4298
 	wdVar := "WDIR"
4299
-	wdVal := "/tmp/"
4299
+	wdVal := "/tmp"
4300 4300
 	addVar := "AFILE"
4301 4301
 	addVal := "addFile"
4302 4302
 	copyVar := "CFILE"