Browse code

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 <dug@us.ibm.com>

Doug Davis authored on 2016/10/05 01:38:00
Showing 4 changed files
... ...
@@ -61,7 +61,7 @@ func SetEscapeToken(s string, d *Directive) error {
61 61
 		return fmt.Errorf("invalid ESCAPE '%s'. Must be ` or \\", s)
62 62
 	}
63 63
 	d.EscapeToken = rune(s[0])
64
-	d.LineContinuationRegex = regexp.MustCompile(`\` + s + `[ \t]*$`)
64
+	d.LineContinuationRegex = regexp.MustCompile(`\` + s + `$`)
65 65
 	return nil
66 66
 }
67 67
 
... ...
@@ -13,8 +13,6 @@ world
13 13
 RUN echo hello \
14 14
 goodbye\
15 15
 frog
16
-RUN echo hello  \  
17
-world
18 16
 RUN echo hi \
19 17
  \
20 18
  world \
... ...
@@ -3,7 +3,6 @@
3 3
 (run "echo hello    world")
4 4
 (run "echo hello  world")
5 5
 (run "echo hello goodbyefrog")
6
-(run "echo hello  world")
7 6
 (run "echo hi   world  goodnight")
8 7
 (run "echo goodbyefrog")
9 8
 (run "echo goodbyefrog")
... ...
@@ -6901,6 +6901,17 @@ func (s *DockerSuite) TestBuildCmdShellArgsEscaped(c *check.C) {
6901 6901
 	}
6902 6902
 }
6903 6903
 
6904
+func (s *DockerSuite) TestContinueCharSpace(c *check.C) {
6905
+	// Test to make sure that we don't treat a \ as a continuation
6906
+	// character IF there are spaces (or tabs) after it on the same line
6907
+	name := "testbuildcont"
6908
+	_, err := buildImage(name, "FROM busybox\nRUN echo hi \\\t\nbye", true)
6909
+	c.Assert(err, check.NotNil, check.Commentf("Build 1 should fail - didn't"))
6910
+
6911
+	_, err = buildImage(name, "FROM busybox\nRUN echo hi \\ \nbye", true)
6912
+	c.Assert(err, check.NotNil, check.Commentf("Build 2 should fail - didn't"))
6913
+}
6914
+
6904 6915
 // Test case for #24912.
6905 6916
 func (s *DockerSuite) TestBuildStepsWithProgress(c *check.C) {
6906 6917
 	name := "testbuildstepswithprogress"