Skip to content

Commit 19da76b

Browse files
Merge pull request #283 from nalind/workdir-trailing-separator
Trim trailing path separators from WORKDIR values
2 parents 5b6b190 + 8fca88b commit 19da76b

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

dispatchers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ func workdir(b *Builder, args []string, attributes map[string]bool, flagArgs []s
372372
workdir = filepath.Join(string(os.PathSeparator), current, workdir)
373373
}
374374

375+
if workdir != string(os.PathSeparator) {
376+
workdir = strings.TrimSuffix(workdir, string(os.PathSeparator))
377+
}
378+
375379
b.RunConfig.WorkingDir = workdir
376380
return nil
377381
}

dockerclient/conformance_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,14 @@ func TestConformanceInternal(t *testing.T) {
484484
Name: "healthcheck",
485485
Dockerfile: "testdata/Dockerfile.healthcheck",
486486
},
487+
{
488+
Name: "workdir-with-trailing-path-separator",
489+
Dockerfile: "testdata/workdir/Dockerfile.trailing",
490+
},
491+
{
492+
Name: "workdir-without-trailing-path-separator",
493+
Dockerfile: "testdata/workdir/Dockerfile.notrailing",
494+
},
487495
}
488496

489497
for i, test := range testCases {
@@ -518,7 +526,7 @@ func TestConformanceExternal(t *testing.T) {
518526
{
519527
Name: "copy and env interaction",
520528
// Tests COPY and other complex interactions of ENV
521-
ContextDir: "16/alpine3.18",
529+
ContextDir: "16/alpine3.20",
522530
Dockerfile: "Dockerfile",
523531
Git: "https://github.com/docker-library/postgres.git",
524532
Ignore: []ignoreFunc{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM busybox
2+
USER daemon
3+
WORKDIR /tmp
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM busybox
2+
USER daemon
3+
WORKDIR /tmp/

0 commit comments

Comments
 (0)