Skip to content

Commit d9aded0

Browse files
authored
caddyfile: Allow heredoc blank lines (#6051)
1 parent 4181c79 commit d9aded0

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

caddyconfig/caddyfile/lexer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ func (l *lexer) finalizeHeredoc(val []rune, marker string) ([]rune, error) {
313313
// iterate over each line and strip the whitespace from the front
314314
var out string
315315
for lineNum, lineText := range lines[:len(lines)-1] {
316+
if lineText == "" {
317+
out += "\n"
318+
continue
319+
}
320+
316321
// find an exact match for the padding
317322
index := strings.Index(lineText, paddingToStrip)
318323

caddyconfig/caddyfile/lexer_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,48 @@ EOF same-line-arg
445445
expectErr: true,
446446
errorMessage: "mismatched leading whitespace in heredoc <<EOF on line #2 [ content], expected whitespace [\t\t] to match the closing marker",
447447
},
448+
{
449+
input: []byte(`heredoc <<EOF
450+
The next line is a blank line
451+
452+
The previous line is a blank line
453+
EOF`),
454+
expected: []Token{
455+
{Line: 1, Text: "heredoc"},
456+
{Line: 1, Text: "The next line is a blank line\n\nThe previous line is a blank line"},
457+
},
458+
},
459+
{
460+
input: []byte(`heredoc <<EOF
461+
One tab indented heredoc with blank next line
462+
463+
One tab indented heredoc with blank previous line
464+
EOF`),
465+
expected: []Token{
466+
{Line: 1, Text: "heredoc"},
467+
{Line: 1, Text: "One tab indented heredoc with blank next line\n\nOne tab indented heredoc with blank previous line"},
468+
},
469+
},
470+
{
471+
input: []byte(`heredoc <<EOF
472+
The next line is a blank line with one tab
473+
474+
The previous line is a blank line with one tab
475+
EOF`),
476+
expected: []Token{
477+
{Line: 1, Text: "heredoc"},
478+
{Line: 1, Text: "The next line is a blank line with one tab\n\t\nThe previous line is a blank line with one tab"},
479+
},
480+
},
481+
{
482+
input: []byte(`heredoc <<EOF
483+
The next line is a blank line with one tab less than the correct indentation
484+
485+
The previous line is a blank line with one tab less than the correct indentation
486+
EOF`),
487+
expectErr: true,
488+
errorMessage: "mismatched leading whitespace in heredoc <<EOF on line #3 [\t], expected whitespace [\t\t] to match the closing marker",
489+
},
448490
}
449491

450492
for i, testCase := range testCases {

0 commit comments

Comments
 (0)