From c369df5c375685f35f5b9f47f5790124c28258c9 Mon Sep 17 00:00:00 2001 From: bbaa Date: Thu, 25 Jan 2024 22:55:00 +0800 Subject: [PATCH] caddyfile: Correctly close the heredoc when the closing marker appears immediately (#6062) --- caddyconfig/caddyfile/lexer.go | 2 +- caddyconfig/caddyfile/lexer_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/caddyconfig/caddyfile/lexer.go b/caddyconfig/caddyfile/lexer.go index 763afb6c..4db63749 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 6cd56855..7389af79 100644 --- a/caddyconfig/caddyfile/lexer_test.go +++ b/caddyconfig/caddyfile/lexer_test.go @@ -285,6 +285,18 @@ EOF same-line-arg }, { input: []byte(`heredoc <