Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Fix parsing panic if variables are not defined #269

Merged
merged 3 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/parser/dockerfile/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package dockerfile

import (
"errors"
"fmt"
"regexp"
"strings"
Expand Down Expand Up @@ -70,6 +71,9 @@ func (d *baseDirective) replaceVars(vars map[string]string) error {
if err != nil {
return d.err(fmt.Errorf("Failed to replace variables in input: %s", err))
}
if len(replaced) == 0 {
return d.err(errors.New("Empty args after replacing variables"))
}
d.Args = replaced
return nil
}
Expand Down
1 change: 1 addition & 0 deletions lib/parser/dockerfile/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestNewCopyDirective(t *testing.T) {
chown string
}{
{"missing args", false, "copy ", nil, "", "", ""},
{"missing args after replace", false, "copy \\", nil, "", "", ""},
{"shell single source", true, `copy src dst`, []string{"src"}, "dst", "", ""},
{"shell multi source", true, `copy src1 src2 dst`, []string{"src1", "src2"}, "dst", "", ""},
{"shell substitution", true, `copy src1 ${prefix}src2 dst$suffix`, []string{"src1", "test_src2"}, "dst_test", "", ""},
Expand Down
1 change: 1 addition & 0 deletions lib/parser/dockerfile/from_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestNewFromDirective(t *testing.T) {
{"bad 'as'", false, "from test_image:trusty sa test_alias", "", ""},
{"substitution", true, "from ${prefix}image:trusty as alias$suffix", "test_image:trusty", "alias_test"},
{"bad substitution", false, "from ${prefiximage:trusty as alias$suffix", "", ""},
{"empty substitution", false, "from ${0:+0}", "test_image", ""},
}

for _, test := range tests {
Expand Down