From 63637b9d277d322a06f24e3195fab48bc2a705d6 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Wed, 15 Oct 2014 03:33:11 +0000 Subject: [PATCH] builder: handle anything we cannot parse the command for as a fatal error. Docker-DCO-1.1-Signed-off-by: Erik Hollensbe (github: erikh) --- builder/parser/parser.go | 5 ++++- .../html-page-yes-really-thanks-lk4d4/Dockerfile | 2 ++ builder/parser/utils.go | 14 +++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 builder/parser/testfiles-negative/html-page-yes-really-thanks-lk4d4/Dockerfile diff --git a/builder/parser/parser.go b/builder/parser/parser.go index c24a925e43..e22ce81317 100644 --- a/builder/parser/parser.go +++ b/builder/parser/parser.go @@ -72,7 +72,10 @@ func parseLine(line string) (string, *Node, error) { return line, nil, nil } - cmd, args := splitCommand(line) + cmd, args, err := splitCommand(line) + if err != nil { + return "", nil, err + } node := &Node{} node.Value = cmd diff --git a/builder/parser/testfiles-negative/html-page-yes-really-thanks-lk4d4/Dockerfile b/builder/parser/testfiles-negative/html-page-yes-really-thanks-lk4d4/Dockerfile new file mode 100644 index 0000000000..90531a4b3e --- /dev/null +++ b/builder/parser/testfiles-negative/html-page-yes-really-thanks-lk4d4/Dockerfile @@ -0,0 +1,2 @@ + + diff --git a/builder/parser/utils.go b/builder/parser/utils.go index f8049be9d4..402ebf68e7 100644 --- a/builder/parser/utils.go +++ b/builder/parser/utils.go @@ -1,6 +1,9 @@ package parser -import "strings" +import ( + "fmt" + "strings" +) // QuoteString walks characters (after trimming), escapes any quotes and // escapes, then wraps the whole thing in quotes. Very useful for generating @@ -66,12 +69,17 @@ func fullDispatch(cmd, args string) (*Node, map[string]bool, error) { // splitCommand takes a single line of text and parses out the cmd and args, // which are used for dispatching to more exact parsing functions. -func splitCommand(line string) (string, string) { +func splitCommand(line string) (string, string, error) { cmdline := TOKEN_WHITESPACE.Split(line, 2) + + if len(cmdline) != 2 { + return "", "", fmt.Errorf("We do not understand this file. Please ensure it is a valid Dockerfile.") + } + cmd := strings.ToLower(cmdline[0]) // the cmd should never have whitespace, but it's possible for the args to // have trailing whitespace. - return cmd, strings.TrimSpace(cmdline[1]) + return cmd, strings.TrimSpace(cmdline[1]), nil } // covers comments and empty lines. Lines should be trimmed before passing to