@marcel91200 / caddy Mirror · read-only / commits / c369df5c
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 18:15 UTC

caddyfile: Correctly close the heredoc when the closing marker appears immediately (#6062)

bbaa committed Jan 25, 2024 at 22:55 UTC c369df5c375685f35f5b9f47f5790124c28258c9
2 files changed +13 -1
caddyconfig/caddyfile/lexer.go
+1 -1
@@ -186,7 +186,7 @@ func (l *lexer) next() (bool, error) {
186 }
187
188 // check if we're done, i.e. that the last few characters are the marker
189 - if len(val) > len(heredocMarker) && heredocMarker == string(val[len(val)-len(heredocMarker):]) {
189 + if len(val) >= len(heredocMarker) && heredocMarker == string(val[len(val)-len(heredocMarker):]) {
190 // set the final value
191 val, err = l.finalizeHeredoc(val, heredocMarker)
192 if err != nil {
caddyconfig/caddyfile/lexer_test.go
+12
@@ -285,6 +285,18 @@ EOF same-line-arg
285 },
286 {
287 input: []byte(`heredoc <<EOF
288 +EOF
289 + HERE same-line-arg
290 + `),
291 + expected: []Token{
292 + {Line: 1, Text: `heredoc`},
293 + {Line: 1, Text: ``},
294 + {Line: 3, Text: `HERE`},
295 + {Line: 3, Text: `same-line-arg`},
296 + },
297 + },
298 + {
299 + input: []byte(`heredoc <<EOF
300 EOF same-line-arg
301 `),
302 expected: []Token{