diff options
author | bbaa <[email protected]> | 2024-02-20 20:29:20 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2024-02-20 12:29:20 +0000 |
commit | 8bbf8ec6299de9967eac756510ee1d92d42a5610 (patch) | |
tree | 19ae52a7c99885d8351821342aa44b8ad45b4edf | |
parent | 4284e39a1783b72225c7ac184205622fdbdec75a (diff) | |
download | caddy-8bbf8ec6299de9967eac756510ee1d92d42a5610.tar.gz caddy-8bbf8ec6299de9967eac756510ee1d92d42a5610.zip |
caddyfile: Assert having a space after heredoc marker to simply check (#6117)
-rw-r--r-- | caddyconfig/caddyfile/formatter.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/caddyconfig/caddyfile/formatter.go b/caddyconfig/caddyfile/formatter.go index 764f79118..d506219c4 100644 --- a/caddyconfig/caddyfile/formatter.go +++ b/caddyconfig/caddyfile/formatter.go @@ -124,18 +124,22 @@ func Format(input []byte) []byte { } // if we're in a heredoc, all characters are read&write as-is if heredoc == heredocOpened { - write(ch) heredocClosingMarker = append(heredocClosingMarker, ch) - if len(heredocClosingMarker) > len(heredocMarker) { + if len(heredocClosingMarker) > len(heredocMarker)+1 { // We assert that the heredocClosingMarker is followed by a unicode.Space heredocClosingMarker = heredocClosingMarker[1:] } // check if we're done - if slices.Equal(heredocClosingMarker, heredocMarker) { + if unicode.IsSpace(ch) && slices.Equal(heredocClosingMarker[:len(heredocClosingMarker)-1], heredocMarker) { heredocMarker = nil heredocClosingMarker = nil heredoc = heredocClosed + } else { + write(ch) + if ch == '\n' { + heredocClosingMarker = heredocClosingMarker[:0] + } + continue } - continue } if last == '<' && space { |