mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
builder: handle escapes without swallowing all of them.
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
parent
7f8cdeb18b
commit
2dac82eb82
2 changed files with 88 additions and 1 deletions
|
@ -24,8 +24,9 @@ func (b *Builder) replaceEnv(str string) string {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefix := match[:idx]
|
||||||
stripped := match[idx+2:]
|
stripped := match[idx+2:]
|
||||||
str = strings.Replace(str, match, "$"+stripped, -1)
|
str = strings.Replace(str, match, prefix+"$"+stripped, -1)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,92 @@ import (
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestBuildHandleEscapes(t *testing.T) {
|
||||||
|
name := "testbuildhandleescapes"
|
||||||
|
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, err := buildImage(name,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
ENV FOO bar
|
||||||
|
VOLUME ${FOO}
|
||||||
|
`, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var result map[string]map[string]struct{}
|
||||||
|
|
||||||
|
res, err := inspectFieldJSON(name, "Config.Volumes")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = unmarshalJSON([]byte(res), &result); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := result["bar"]; !ok {
|
||||||
|
t.Fatal("Could not find volume bar set from env foo in volumes table")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = buildImage(name,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
ENV FOO bar
|
||||||
|
VOLUME \${FOO}
|
||||||
|
`, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err = inspectFieldJSON(name, "Config.Volumes")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = unmarshalJSON([]byte(res), &result); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := result["${FOO}"]; !ok {
|
||||||
|
t.Fatal("Could not find volume ${FOO} set from env foo in volumes table")
|
||||||
|
}
|
||||||
|
|
||||||
|
// this test in particular provides *7* backslashes and expects 6 to come back.
|
||||||
|
// Like above, the first escape is swallowed and the rest are treated as
|
||||||
|
// literals, this one is just less obvious because of all the character noise.
|
||||||
|
|
||||||
|
_, err = buildImage(name,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
ENV FOO bar
|
||||||
|
VOLUME \\\\\\\${FOO}
|
||||||
|
`, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err = inspectFieldJSON(name, "Config.Volumes")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = unmarshalJSON([]byte(res), &result); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := result[`\\\\\\${FOO}`]; !ok {
|
||||||
|
t.Fatal(`Could not find volume \\\\\\${FOO} set from env foo in volumes table`)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - handle escapes")
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuildOnBuildLowercase(t *testing.T) {
|
func TestBuildOnBuildLowercase(t *testing.T) {
|
||||||
name := "testbuildonbuildlowercase"
|
name := "testbuildonbuildlowercase"
|
||||||
name2 := "testbuildonbuildlowercase2"
|
name2 := "testbuildonbuildlowercase2"
|
||||||
|
|
Loading…
Reference in a new issue