Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit a15dfd0

Browse files
Minor change to only include internal values for heredoc commands, since we'll parse whole structure in separate new structure
1 parent aa700eb commit a15dfd0

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

parse.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ func ParseReader(file io.Reader) ([]Command, error) {
7474
}
7575

7676
cmd.Json = child.Attributes["json"]
77-
for n := child.Next; n != nil; n = n.Next {
78-
cmd.Value = append(cmd.Value, n.Value)
77+
78+
if len(child.Heredocs) == 0 {
79+
for n := child.Next; n != nil; n = n.Next {
80+
cmd.Value = append(cmd.Value, n.Value)
81+
}
7982
}
8083

8184
if len(child.Heredocs) != 0 {
@@ -84,7 +87,7 @@ func ParseReader(file io.Reader) ([]Command, error) {
8487
cmd.Original = cmd.Original + "\n"
8588
for _, heredoc := range child.Heredocs {
8689
cmd.Original = cmd.Original + heredoc.Content + heredoc.Name + "\n"
87-
cmd.Value = append(cmd.Value, heredoc.Content+heredoc.Name+"\n")
90+
cmd.Value = append(cmd.Value, heredoc.Content)
8891
}
8992
}
9093

parse_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ EOF
133133
StartLine: 1,
134134
EndLine: 5,
135135
Flags: []string{},
136-
Value: []string{"<<EOF", "source $HOME/.bashrc && echo $HOME\necho \"Hello\" >> /hello\necho \"World!\" >> /hello\nEOF\n"},
136+
Value: []string{"source $HOME/.bashrc && echo $HOME\necho \"Hello\" >> /hello\necho \"World!\" >> /hello\n"},
137137
},
138138
}
139139
assert.Equal(t, expected, cmds)
@@ -155,7 +155,7 @@ FILE2
155155
StartLine: 1,
156156
EndLine: 5,
157157
Flags: []string{},
158-
Value: []string{"<<FILE1", "<<FILE2", "/dest", "content 1\nFILE1\n", "content 2\nFILE2\n"},
158+
Value: []string{"content 1\n", "content 2\n"},
159159
},
160160
}
161161
assert.Equal(t, expected, cmds)

tests/dockerfile_test.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,9 @@ def test_heredoc_string_success():
116116
dockerfile.Command(
117117
cmd='RUN', sub_cmd=None, json=False, flags=(),
118118
value=(
119-
'<<EOF',
120119
'source $HOME/.bashrc && echo $HOME\n'
121120
'echo "Hello" >> /hello\n'
122-
'echo "World!" >> /hello\n'
123-
'EOF\n',
121+
'echo "World!" >> /hello\n',
124122
),
125123
start_line=1, end_line=5, original=test_string,
126124
),
@@ -140,13 +138,8 @@ def test_heredoc_string_multiple_success():
140138
dockerfile.Command(
141139
cmd='COPY', sub_cmd=None, json=False, flags=(),
142140
value=(
143-
'<<FILE1',
144-
'<<FILE2',
145-
'/dest',
146-
'content 1\n'
147-
'FILE1\n',
148-
'content 2\n'
149-
'FILE2\n',
141+
'content 1\n',
142+
'content 2\n',
150143
),
151144
start_line=1, end_line=5, original=test_string,
152145
),

0 commit comments

Comments
 (0)