Skip to content

Commit

Permalink
caddyfile: Correctly close the heredoc when the closing marker appear…
Browse files Browse the repository at this point in the history
…s immediately
  • Loading branch information
bbaa-bbaa committed Jan 25, 2024
1 parent b9c40e7 commit 449bd33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion caddyconfig/caddyfile/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (l *lexer) next() (bool, error) {
}

// check if we're done, i.e. that the last few characters are the marker
if len(val) > len(heredocMarker) && heredocMarker == string(val[len(val)-len(heredocMarker):]) {
if len(val) >= len(heredocMarker) && heredocMarker == string(val[len(val)-len(heredocMarker):]) {
// set the final value
val, err = l.finalizeHeredoc(val, heredocMarker)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions caddyconfig/caddyfile/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ EOF same-line-arg
},
{
input: []byte(`heredoc <<EOF
EOF
HERE same-line-arg
`),
expected: []Token{
{Line: 1, Text: `heredoc`},
{Line: 1, Text: ``},
{Line: 3, Text: `HERE`},
{Line: 3, Text: `same-line-arg`},
},
},
{
input: []byte(`heredoc <<EOF
EOF same-line-arg
`),
expected: []Token{
Expand Down

0 comments on commit 449bd33

Please sign in to comment.