Skip to content

Commit

Permalink
caddyfile: Assert having a space after heredoc marker to simply check (
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaa-bbaa authored Feb 20, 2024
1 parent 4284e39 commit 8bbf8ec
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions caddyconfig/caddyfile/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8bbf8ec

Please sign in to comment.