Skip to content

Commit

Permalink
Merge pull request #9980 from erikh/parser-with-no-command
Browse files Browse the repository at this point in the history
Fix a parser error where an empty RUN statement would cause a panic
  • Loading branch information
duglin committed Jan 9, 2015
2 parents 3fbf723 + 09e3467 commit 32cde64
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion builder/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package parser

import (
"bufio"
"fmt"
"io"
"regexp"
"strings"
Expand Down Expand Up @@ -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(`^#.*$`)
)

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM dockerfile/rabbitmq

RUN
rabbitmq-plugins enable \
rabbitmq_shovel \
rabbitmq_shovel_management \
rabbitmq_federation \
rabbitmq_federation_management
21 changes: 21 additions & 0 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 32cde64

Please sign in to comment.