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

Commit 5294663

Browse files
Return contents of Value field to have, for the heredocs case, the parts of the first line of the command, which makes more sense
1 parent bbd2a1e commit 5294663

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

parse.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ func ParseReader(file io.Reader) ([]Command, error) {
8383

8484
cmd.Json = child.Attributes["json"]
8585

86-
if len(child.Heredocs) == 0 {
87-
for n := child.Next; n != nil; n = n.Next {
88-
cmd.Value = append(cmd.Value, n.Value)
89-
}
86+
for n := child.Next; n != nil; n = n.Next {
87+
cmd.Value = append(cmd.Value, n.Value)
9088
}
9189

9290
if len(child.Heredocs) != 0 {
@@ -95,7 +93,6 @@ func ParseReader(file io.Reader) ([]Command, error) {
9593
cmd.Original = cmd.Original + "\n"
9694
for _, heredoc := range child.Heredocs {
9795
cmd.Original = cmd.Original + heredoc.Content + heredoc.Name + "\n"
98-
cmd.Value = append(cmd.Value, heredoc.Content)
9996
cmd.Heredocs = append(cmd.Heredocs, Heredoc{Name: heredoc.Name,
10097
FileDescriptor: heredoc.FileDescriptor,
10198
Content: heredoc.Content})

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{"source $HOME/.bashrc && echo $HOME\necho \"Hello\" >> /hello\necho \"World!\" >> /hello\n"},
136+
Value: []string{"3<<EOF"},
137137
Heredocs: []Heredoc{
138138
Heredoc{
139139
Name: "EOF",
@@ -161,7 +161,7 @@ FILE2
161161
StartLine: 1,
162162
EndLine: 5,
163163
Flags: []string{},
164-
Value: []string{"content 1\n", "content 2\n"},
164+
Value: []string{"<<FILE1", "<<FILE2", "/dest"},
165165
Heredocs: []Heredoc{
166166
Heredoc{
167167
Name: "FILE1",

tests/dockerfile_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ def test_heredoc_string_success():
116116
dockerfile.Command(
117117
cmd='RUN', sub_cmd=None, json=False, flags=(),
118118
value=(
119-
'source $HOME/.bashrc && echo $HOME\n'
120-
'echo "Hello" >> /hello\n'
121-
'echo "World!" >> /hello\n',
119+
'3<<EOF',
122120
),
123121
start_line=1, end_line=5, original=test_string,
124122
heredocs=(
@@ -147,8 +145,9 @@ def test_heredoc_string_multiple_success():
147145
dockerfile.Command(
148146
cmd='COPY', sub_cmd=None, json=False, flags=(),
149147
value=(
150-
'content 1\n',
151-
'content 2\n',
148+
'<<FILE1',
149+
'<<FILE2',
150+
'/dest',
152151
),
153152
start_line=1, end_line=5, original=test_string,
154153
heredocs=(

0 commit comments

Comments
 (0)