1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix builder/parser so it keeps some whitespace on split lines.

If previous line ends with whitespace, or next line starts with whitepsace
we need to preserve a space otherwise things line:
RUN echo\
   hello
will appear as: RUN echohello

Noticed this while looking at #5744 because he had lines ending in &&\

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2014-10-02 16:58:53 -07:00
parent f69a262464
commit f440c6b224
10 changed files with 53 additions and 15 deletions

View file

@ -6,6 +6,7 @@ import (
"io"
"regexp"
"strings"
"unicode"
)
// Node is a structure used to represent a parse tree.
@ -96,14 +97,14 @@ func Parse(rwc io.Reader) (*Node, error) {
scanner := bufio.NewScanner(rwc)
for scanner.Scan() {
line, child, err := parseLine(strings.TrimSpace(scanner.Text()))
line, child, err := parseLine(strings.TrimLeftFunc(scanner.Text(), unicode.IsSpace))
if err != nil {
return nil, err
}
if line != "" && child == nil {
for scanner.Scan() {
newline := strings.TrimSpace(scanner.Text())
newline := scanner.Text()
if newline == "" {
continue

View file

@ -71,8 +71,8 @@ func TestTestData(t *testing.T) {
}
if ast.Dump()+"\n" != string(content) {
fmt.Fprintln(os.Stderr, ast.Dump())
fmt.Fprintln(os.Stderr, string(content))
fmt.Fprintln(os.Stderr, "Result:\n"+ast.Dump())
fmt.Fprintln(os.Stderr, "Expected:\n"+string(content))
t.Fatalf("%s: AST dump of dockerfile does not match result", dir.Name())
}

View file

@ -0,0 +1,28 @@
FROM ubuntu:14.04
RUN echo hello\
world\
goodnight \
moon\
light\
ning
RUN echo hello \
world
RUN echo hello \
world
RUN echo hello \
goodbye\
frog
RUN echo hello \
RUN echo hi \
\
world \
\
good\
\
night
RUN echo goodbye\
frog
RUN echo good\
bye\
frog

View file

@ -0,0 +1,9 @@
(from "ubuntu:14.04")
(run "echo hello world goodnight moon lightning")
(run "echo hello world")
(run "echo hello world")
(run "echo hello goodbyefrog")
(run "echo hello \\")
(run "echo hi world goodnight")
(run "echo goodbyefrog")
(run "echo goodbyefrog")