From 105bc63295a7126798d3722a0e205c5ead4e2b1c Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Tue, 4 Oct 2016 09:38:00 -0700 Subject: [PATCH] Require continuation char to be last char in a line While look at #27039 I noticed that we allow for whitespace after the continuation char (\\) which is wrong. It needs to be the very last char in the line. Signed-off-by: Doug Davis --- builder/dockerfile/parser/parser.go | 2 +- .../parser/testfiles/continueIndent/Dockerfile | 2 -- .../dockerfile/parser/testfiles/continueIndent/result | 1 - integration-cli/docker_cli_build_test.go | 11 +++++++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/builder/dockerfile/parser/parser.go b/builder/dockerfile/parser/parser.go index b1dd8f2fdd..d89bdfbaf4 100644 --- a/builder/dockerfile/parser/parser.go +++ b/builder/dockerfile/parser/parser.go @@ -61,7 +61,7 @@ func SetEscapeToken(s string, d *Directive) error { return fmt.Errorf("invalid ESCAPE '%s'. Must be ` or \\", s) } d.EscapeToken = rune(s[0]) - d.LineContinuationRegex = regexp.MustCompile(`\` + s + `[ \t]*$`) + d.LineContinuationRegex = regexp.MustCompile(`\` + s + `$`) return nil } diff --git a/builder/dockerfile/parser/testfiles/continueIndent/Dockerfile b/builder/dockerfile/parser/testfiles/continueIndent/Dockerfile index 42b324e77b..97f915f16b 100644 --- a/builder/dockerfile/parser/testfiles/continueIndent/Dockerfile +++ b/builder/dockerfile/parser/testfiles/continueIndent/Dockerfile @@ -13,8 +13,6 @@ world RUN echo hello \ goodbye\ frog -RUN echo hello \ -world RUN echo hi \ \ world \ diff --git a/builder/dockerfile/parser/testfiles/continueIndent/result b/builder/dockerfile/parser/testfiles/continueIndent/result index 268ae073c8..76a1cb6f21 100644 --- a/builder/dockerfile/parser/testfiles/continueIndent/result +++ b/builder/dockerfile/parser/testfiles/continueIndent/result @@ -3,7 +3,6 @@ (run "echo hello world") (run "echo hello world") (run "echo hello goodbyefrog") -(run "echo hello world") (run "echo hi world goodnight") (run "echo goodbyefrog") (run "echo goodbyefrog") diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index dd8a8d90c8..a06969d9ee 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -6901,6 +6901,17 @@ func (s *DockerSuite) TestBuildCmdShellArgsEscaped(c *check.C) { } } +func (s *DockerSuite) TestContinueCharSpace(c *check.C) { + // Test to make sure that we don't treat a \ as a continuation + // character IF there are spaces (or tabs) after it on the same line + name := "testbuildcont" + _, err := buildImage(name, "FROM busybox\nRUN echo hi \\\t\nbye", true) + c.Assert(err, check.NotNil, check.Commentf("Build 1 should fail - didn't")) + + _, err = buildImage(name, "FROM busybox\nRUN echo hi \\ \nbye", true) + c.Assert(err, check.NotNil, check.Commentf("Build 2 should fail - didn't")) +} + // Test case for #24912. func (s *DockerSuite) TestBuildStepsWithProgress(c *check.C) { name := "testbuildstepswithprogress"