mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Return error if basename is expanded to blank
Fix: https://github.com/moby/moby/issues/37325 Signed-off-by: Yuichiro Kaneko <spiketeika@gmail.com>
This commit is contained in:
parent
b711437bbd
commit
c9542d313e
2 changed files with 24 additions and 2 deletions
|
@ -274,11 +274,17 @@ func (d *dispatchRequest) getImageOrStage(name string, platform *specs.Platform)
|
|||
}
|
||||
return imageMount.Image(), nil
|
||||
}
|
||||
func (d *dispatchRequest) getFromImage(shlex *shell.Lex, name string, platform *specs.Platform) (builder.Image, error) {
|
||||
name, err := d.getExpandedString(shlex, name)
|
||||
func (d *dispatchRequest) getFromImage(shlex *shell.Lex, basename string, platform *specs.Platform) (builder.Image, error) {
|
||||
name, err := d.getExpandedString(shlex, basename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Empty string is interpreted to FROM scratch by images.GetImageAndReleasableLayer,
|
||||
// so validate expanded result is not empty.
|
||||
if name == "" {
|
||||
return nil, errors.Errorf("base name (%s) should not be blank", basename)
|
||||
}
|
||||
|
||||
return d.getImageOrStage(name, platform)
|
||||
}
|
||||
|
||||
|
|
|
@ -157,6 +157,22 @@ func TestFromWithArg(t *testing.T) {
|
|||
assert.Check(t, is.Len(sb.state.buildArgs.GetAllMeta(), 1))
|
||||
}
|
||||
|
||||
func TestFromWithArgButBuildArgsNotGiven(t *testing.T) {
|
||||
b := newBuilderWithMockBackend()
|
||||
args := NewBuildArgs(make(map[string]*string))
|
||||
|
||||
metaArg := instructions.ArgCommand{}
|
||||
cmd := &instructions.Stage{
|
||||
BaseName: "${THETAG}",
|
||||
}
|
||||
err := processMetaArg(metaArg, shell.NewLex('\\'), args)
|
||||
|
||||
sb := newDispatchRequest(b, '\\', nil, args, newStagesBuildResults())
|
||||
assert.NilError(t, err)
|
||||
err = initializeStage(sb, cmd)
|
||||
assert.Error(t, err, "base name (${THETAG}) should not be blank")
|
||||
}
|
||||
|
||||
func TestFromWithUndefinedArg(t *testing.T) {
|
||||
tag, expected := "sometag", "expectedthisid"
|
||||
|
||||
|
|
Loading…
Reference in a new issue