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, 17:00 UTC
caddyfile: Assert having a space after heredoc marker to simply check (#6117)
bbaa committed
Feb 20, 2024 at 20:29 UTC
8bbf8ec6299de9967eac756510ee1d92d42a5610
1 file changed
+8
-4
caddyconfig/caddyfile/formatter.go
+8
-4
@@ -124,18 +124,22 @@ func Format(input []byte) []byte {
124
}
125
// if we're in a heredoc, all characters are read&write as-is
126
if heredoc == heredocOpened {
127
- write(ch)
127
heredocClosingMarker = append(heredocClosingMarker, ch)
129
- if len(heredocClosingMarker) > len(heredocMarker) {
128
+ if len(heredocClosingMarker) > len(heredocMarker)+1 { // We assert that the heredocClosingMarker is followed by a unicode.Space
129
heredocClosingMarker = heredocClosingMarker[1:]
130
}
131
// check if we're done
133
- if slices.Equal(heredocClosingMarker, heredocMarker) {
132
+ if unicode.IsSpace(ch) && slices.Equal(heredocClosingMarker[:len(heredocClosingMarker)-1], heredocMarker) {
133
heredocMarker = nil
134
heredocClosingMarker = nil
135
heredoc = heredocClosed
136
+ } else {
137
+ write(ch)
138
+ if ch == '\n' {
139
+ heredocClosingMarker = heredocClosingMarker[:0]
140
+ }
141
+ continue
142
}
138
- continue
143
}
144
145
if last == '<' && space {