From 96f342f7030c3955900f8f2ddf06b0d36b1d993c Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Wed, 15 Oct 2014 08:44:14 +0000 Subject: [PATCH] builder: comments should also be elided in the middle of statements following a line continuation. Docker-DCO-1.1-Signed-off-by: Erik Hollensbe (github: erikh) --- builder/parser/parser.go | 7 ++++--- builder/parser/testfiles/continueIndent/Dockerfile | 7 +++++++ builder/parser/testfiles/continueIndent/result | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/builder/parser/parser.go b/builder/parser/parser.go index ae721cca46..0061779201 100644 --- a/builder/parser/parser.go +++ b/builder/parser/parser.go @@ -98,11 +98,12 @@ func Parse(rwc io.Reader) (*Node, error) { scanner := bufio.NewScanner(rwc) for scanner.Scan() { - if scanner.Text() == "" { + scannedLine := strings.TrimLeftFunc(scanner.Text(), unicode.IsSpace) + if stripComments(scannedLine) == "" { continue } - line, child, err := parseLine(strings.TrimLeftFunc(scanner.Text(), unicode.IsSpace)) + line, child, err := parseLine(scannedLine) if err != nil { return nil, err } @@ -111,7 +112,7 @@ func Parse(rwc io.Reader) (*Node, error) { for scanner.Scan() { newline := scanner.Text() - if newline == "" { + if stripComments(strings.TrimSpace(newline)) == "" { continue } diff --git a/builder/parser/testfiles/continueIndent/Dockerfile b/builder/parser/testfiles/continueIndent/Dockerfile index 6ce6c06fb7..454fdcc628 100644 --- a/builder/parser/testfiles/continueIndent/Dockerfile +++ b/builder/parser/testfiles/continueIndent/Dockerfile @@ -26,3 +26,10 @@ frog RUN echo good\ bye\ frog + +RUN echo hello \ +# this is a comment + +# this is a comment with a blank line surrounding it + +this is some more useful stuff diff --git a/builder/parser/testfiles/continueIndent/result b/builder/parser/testfiles/continueIndent/result index e440b836d4..9605558106 100644 --- a/builder/parser/testfiles/continueIndent/result +++ b/builder/parser/testfiles/continueIndent/result @@ -7,3 +7,4 @@ (run "echo hi world goodnight") (run "echo goodbyefrog") (run "echo goodbyefrog") +(run "echo hello this is some more useful stuff")