diff options
author | bbaa <[email protected]> | 2024-01-25 22:55:00 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2024-01-25 14:55:00 +0000 |
commit | c369df5c375685f35f5b9f47f5790124c28258c9 (patch) | |
tree | 46dd735793724b7a512c49d7d4eace5a03827373 /caddyconfig | |
parent | 7c48b5fdbbd1e4a71023328fdb33c48f3346046d (diff) | |
download | caddy-c369df5c375685f35f5b9f47f5790124c28258c9.tar.gz caddy-c369df5c375685f35f5b9f47f5790124c28258c9.zip |
caddyfile: Correctly close the heredoc when the closing marker appears immediately (#6062)
Diffstat (limited to 'caddyconfig')
-rw-r--r-- | caddyconfig/caddyfile/lexer.go | 2 | ||||
-rw-r--r-- | caddyconfig/caddyfile/lexer_test.go | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/caddyconfig/caddyfile/lexer.go b/caddyconfig/caddyfile/lexer.go index 763afb6c2..4db63749b 100644 --- a/caddyconfig/caddyfile/lexer.go +++ b/caddyconfig/caddyfile/lexer.go @@ -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 { diff --git a/caddyconfig/caddyfile/lexer_test.go b/caddyconfig/caddyfile/lexer_test.go index 6cd568557..7389af79b 100644 --- a/caddyconfig/caddyfile/lexer_test.go +++ b/caddyconfig/caddyfile/lexer_test.go @@ -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{ |