Make sure that as we build the CMD/ENTRYPOINT cache strings that we don't
treat ["echo","hi"] and ["echo hi"] as the same thing due to the fact that
we're just doing a strcat on the array.
Closes #10097
Signed-off-by: Doug Davis <dug@us.ibm.com>
... | ... |
@@ -272,7 +272,7 @@ func cmd(b *Builder, args []string, attributes map[string]bool, original string) |
272 | 272 |
b.Config.Cmd = append([]string{"/bin/sh", "-c"}, b.Config.Cmd...) |
273 | 273 |
} |
274 | 274 |
|
275 |
- if err := b.commit("", b.Config.Cmd, fmt.Sprintf("CMD %v", b.Config.Cmd)); err != nil { |
|
275 |
+ if err := b.commit("", b.Config.Cmd, fmt.Sprintf("CMD %q", b.Config.Cmd)); err != nil { |
|
276 | 276 |
return err |
277 | 277 |
} |
278 | 278 |
|
... | ... |
@@ -312,7 +312,7 @@ func entrypoint(b *Builder, args []string, attributes map[string]bool, original |
312 | 312 |
b.Config.Cmd = nil |
313 | 313 |
} |
314 | 314 |
|
315 |
- if err := b.commit("", b.Config.Cmd, fmt.Sprintf("ENTRYPOINT %v", b.Config.Entrypoint)); err != nil { |
|
315 |
+ if err := b.commit("", b.Config.Cmd, fmt.Sprintf("ENTRYPOINT %q", b.Config.Entrypoint)); err != nil { |
|
316 | 316 |
return err |
317 | 317 |
} |
318 | 318 |
|
... | ... |
@@ -3902,6 +3902,44 @@ func TestBuildCmdShDashC(t *testing.T) { |
3902 | 3902 |
logDone("build - cmd should have sh -c for non-json") |
3903 | 3903 |
} |
3904 | 3904 |
|
3905 |
+func TestBuildCmdSpaces(t *testing.T) { |
|
3906 |
+ // Test to make sure that when we strcat arrays we take into account |
|
3907 |
+ // the arg separator to make sure ["echo","hi"] and ["echo hi"] don't |
|
3908 |
+ // look the same |
|
3909 |
+ name := "testbuildcmdspaces" |
|
3910 |
+ defer deleteImages(name) |
|
3911 |
+ var id1 string |
|
3912 |
+ var id2 string |
|
3913 |
+ var err error |
|
3914 |
+ |
|
3915 |
+ if id1, err = buildImage(name, "FROM busybox\nCMD [\"echo hi\"]\n", true); err != nil { |
|
3916 |
+ t.Fatal(err) |
|
3917 |
+ } |
|
3918 |
+ |
|
3919 |
+ if id2, err = buildImage(name, "FROM busybox\nCMD [\"echo\", \"hi\"]\n", true); err != nil { |
|
3920 |
+ t.Fatal(err) |
|
3921 |
+ } |
|
3922 |
+ |
|
3923 |
+ if id1 == id2 { |
|
3924 |
+ t.Fatal("Should not have resulted in the same CMD") |
|
3925 |
+ } |
|
3926 |
+ |
|
3927 |
+ // Now do the same with ENTRYPOINT |
|
3928 |
+ if id1, err = buildImage(name, "FROM busybox\nENTRYPOINT [\"echo hi\"]\n", true); err != nil { |
|
3929 |
+ t.Fatal(err) |
|
3930 |
+ } |
|
3931 |
+ |
|
3932 |
+ if id2, err = buildImage(name, "FROM busybox\nENTRYPOINT [\"echo\", \"hi\"]\n", true); err != nil { |
|
3933 |
+ t.Fatal(err) |
|
3934 |
+ } |
|
3935 |
+ |
|
3936 |
+ if id1 == id2 { |
|
3937 |
+ t.Fatal("Should not have resulted in the same ENTRYPOINT") |
|
3938 |
+ } |
|
3939 |
+ |
|
3940 |
+ logDone("build - cmd with spaces") |
|
3941 |
+} |
|
3942 |
+ |
|
3905 | 3943 |
func TestBuildCmdJSONNoShDashC(t *testing.T) { |
3906 | 3944 |
name := "testbuildcmdjson" |
3907 | 3945 |
defer deleteImages(name) |