@@ -214,7 +214,7 @@ func formatEnv(n *ExtendedNode, c *Config) string {
214214
215215 // Otherwise, we have a valid env command; fall back to original if parsing fails
216216 originalTrimmed := strings .TrimLeft (n .OriginalMultiline , " \t " )
217- parts := regexp .MustCompile (" " ).Split (originalTrimmed , 2 )
217+ parts := regexp .MustCompile ("[ \t ] " ).Split (originalTrimmed , 2 )
218218 if len (parts ) < 2 {
219219 return n .OriginalMultiline
220220 }
@@ -255,6 +255,7 @@ func formatShell(content string, hereDoc bool, c *Config) string {
255255 content = strings .Join (lines , "" )
256256
257257 content = lineComment .ReplaceAllString (content , "$1`$2#`\\ " )
258+ // fmt.Printf("Content-1: %s\n", content)
258259
259260 /*
260261 ```
@@ -270,10 +271,11 @@ func formatShell(content string, hereDoc bool, c *Config) string {
270271 ```
271272 */
272273
273- commentContinuation := regexp .MustCompile (`(\\(?:\s*` + "`#.*#`" + `\\){1,}\s*)&&` )
274- content = commentContinuation .ReplaceAllString (content , "&&$1" )
274+ // The (.[^\\]) prevents an edge case with '&& \'. See tests/in/andissue.dockerfile
275+ commentContinuation := regexp .MustCompile (`(\\(?:\s*` + "`#.*#`" + `\\){1,}\s*)&&(.[^\\])` )
276+ content = commentContinuation .ReplaceAllString (content , "&&$1$2" )
275277
276- // log .Printf("Content0: %s\n", content)
278+ // fmt .Printf("Content0: %s\n", content)
277279 lines = strings .SplitAfter (content , "\n " )
278280 /**
279281 if the next line is not a comment, and we didn't start with a continuation, don't add the `&&`.
@@ -425,12 +427,12 @@ func formatBasic(n *ExtendedNode, c *Config) string {
425427
426428 value , success := GetHeredoc (n )
427429 if ! success {
428- parts := regexp .MustCompile (" " ).Split (originalTrimmed , 2 )
430+ parts := regexp .MustCompile ("[ \t ] " ).Split (originalTrimmed , 2 )
429431 if len (parts ) < 2 {
430432 // No argument after directive; just return the directive itself
431433 return strings .ToUpper (n .Value ) + "\n "
432434 }
433- value = parts [1 ]
435+ value = strings . TrimLeft ( parts [1 ], " \t " )
434436 }
435437 return IndentFollowingLines (strings .ToUpper (n .Value )+ " " + value , c .IndentSize )
436438}
0 commit comments