From 2fd736ac10c1c46d1001373d887cb99b3d8ee824 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 27 Sep 2017 22:18:24 +0200 Subject: [PATCH] Warn on empty continuation lines only, not for comments Commit 8d1ae76dcbbb73d8e20c6a14a7d3fe2410b95f55 added deprecation warnings for empty continuation lines, but also treated comment-only lines as empty. This patch distinguishes empty continuation lines from comment-only lines, and only outputs warnings for the former. Signed-off-by: Sebastiaan van Stijn --- builder/dockerfile/parser/parser.go | 10 +++++++++- builder/dockerfile/parser/parser_test.go | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/builder/dockerfile/parser/parser.go b/builder/dockerfile/parser/parser.go index 4003cba465..42a84c630c 100644 --- a/builder/dockerfile/parser/parser.go +++ b/builder/dockerfile/parser/parser.go @@ -290,6 +290,10 @@ func Parse(rwc io.Reader) (*Result, error) { } currentLine++ + if isComment(scanner.Bytes()) { + // original line was a comment (processLine strips comments) + continue + } if isEmptyContinuationLine(bytesRead) { hasEmptyContinuationLine = true continue @@ -331,8 +335,12 @@ func trimWhitespace(src []byte) []byte { return bytes.TrimLeftFunc(src, unicode.IsSpace) } +func isComment(line []byte) bool { + return tokenComment.Match(trimWhitespace(line)) +} + func isEmptyContinuationLine(line []byte) bool { - return len(trimComments(trimWhitespace(line))) == 0 + return len(trimWhitespace(line)) == 0 } var utf8bom = []byte{0xEF, 0xBB, 0xBF} diff --git a/builder/dockerfile/parser/parser_test.go b/builder/dockerfile/parser/parser_test.go index bb057ecab3..5f354bb139 100644 --- a/builder/dockerfile/parser/parser_test.go +++ b/builder/dockerfile/parser/parser_test.go @@ -141,6 +141,13 @@ RUN something \ RUN another \ thing +RUN non-indented \ +# this is a comment + after-comment + +RUN indented \ + # this is an indented comment + comment `) result, err := Parse(dockerfile)