mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix a parser error where an empty RUN statement would cause a panic
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
parent
8916e2582b
commit
09e3467452
3 changed files with 35 additions and 1 deletions
|
@ -3,6 +3,7 @@ package parser
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
@ -32,7 +33,7 @@ type Node struct {
|
|||
var (
|
||||
dispatch map[string]func(string) (*Node, map[string]bool, error)
|
||||
TOKEN_WHITESPACE = regexp.MustCompile(`[\t\v\f\r ]+`)
|
||||
TOKEN_LINE_CONTINUATION = regexp.MustCompile(`\\\s*$`)
|
||||
TOKEN_LINE_CONTINUATION = regexp.MustCompile(`\\[ \t]*$`)
|
||||
TOKEN_COMMENT = regexp.MustCompile(`^#.*$`)
|
||||
)
|
||||
|
||||
|
@ -77,6 +78,10 @@ func parseLine(line string) (string, *Node, error) {
|
|||
return "", nil, err
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return "", nil, fmt.Errorf("Instruction %q is empty; cannot continue", cmd)
|
||||
}
|
||||
|
||||
node := &Node{}
|
||||
node.Value = cmd
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
FROM dockerfile/rabbitmq
|
||||
|
||||
RUN
|
||||
rabbitmq-plugins enable \
|
||||
rabbitmq_shovel \
|
||||
rabbitmq_shovel_management \
|
||||
rabbitmq_federation \
|
||||
rabbitmq_federation_management
|
|
@ -22,6 +22,27 @@ import (
|
|||
"github.com/docker/docker/pkg/archive"
|
||||
)
|
||||
|
||||
func TestBuildEmptyWhitespace(t *testing.T) {
|
||||
name := "testbuildemptywhitespace"
|
||||
defer deleteImages(name)
|
||||
|
||||
_, err := buildImage(
|
||||
name,
|
||||
`
|
||||
FROM busybox
|
||||
RUN
|
||||
quux \
|
||||
bar
|
||||
`,
|
||||
true)
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("no error when dealing with a RUN statement with no content on the same line")
|
||||
}
|
||||
|
||||
logDone("build - statements with whitespace and no content should generate a parse error")
|
||||
}
|
||||
|
||||
func TestBuildShCmdJSONEntrypoint(t *testing.T) {
|
||||
name := "testbuildshcmdjsonentrypoint"
|
||||
defer deleteImages(name)
|
||||
|
|
Loading…
Reference in a new issue