Revert "caddyfile: Reject long heredoc markers (#6098)" (#6100)

This reverts commit e7a534d0a3.
This commit is contained in:
Mohammed Al Sahaf 2024-02-12 21:06:22 +03:00 committed by GitHub
parent f9e11158bc
commit 21744b6c4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 40 deletions

View file

@ -16,7 +16,6 @@ package caddyfile
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"unicode" "unicode"
@ -119,10 +118,6 @@ func Format(input []byte) []byte {
heredoc = heredocClosed heredoc = heredocClosed
} else { } else {
heredocMarker = append(heredocMarker, ch) heredocMarker = append(heredocMarker, ch)
if len(heredocMarker) > 32 {
errorString := fmt.Sprintf("heredoc marker too long: <<%s", string(heredocMarker))
panic(errorString)
}
write(ch) write(ch)
continue continue
} }

View file

@ -15,8 +15,6 @@
package caddyfile package caddyfile
import ( import (
"fmt"
"os"
"strings" "strings"
"testing" "testing"
) )
@ -26,7 +24,6 @@ func TestFormatter(t *testing.T) {
description string description string
input string input string
expect string expect string
panics bool
}{ }{
{ {
description: "very simple", description: "very simple",
@ -437,36 +434,18 @@ block2 {
} }
`, `,
}, },
{
description: "very long heredoc from fuzzer",
input: func() string {
bs, _ := os.ReadFile("testdata/clusterfuzz-testcase-minimized-fuzz-format-5806400649363456")
return string(bs)
}(),
panics: true,
},
} { } {
t.Run(fmt.Sprintf("test case %d: %s", i, tc.description), func(t *testing.T) { // the formatter should output a trailing newline,
if tc.panics { // even if the tests aren't written to expect that
defer func() { if !strings.HasSuffix(tc.expect, "\n") {
if r := recover(); r == nil { tc.expect += "\n"
t.Errorf("[TEST %d: %s] Expected panic, but got none", i, tc.description) }
}
}()
}
// the formatter should output a trailing newline, actual := Format([]byte(tc.input))
// even if the tests aren't written to expect that
if !strings.HasSuffix(tc.expect, "\n") {
tc.expect += "\n"
}
actual := Format([]byte(tc.input)) if string(actual) != tc.expect {
t.Errorf("\n[TEST %d: %s]\n====== EXPECTED ======\n%s\n====== ACTUAL ======\n%s^^^^^^^^^^^^^^^^^^^^^",
if !tc.panics && string(actual) != tc.expect { i, tc.description, string(tc.expect), string(actual))
t.Errorf("\n[TEST %d: %s]\n====== EXPECTED ======\n%s\n====== ACTUAL ======\n%s^^^^^^^^^^^^^^^^^^^^^", }
i, tc.description, string(tc.expect), string(actual))
}
})
} }
} }

View file

@ -149,10 +149,6 @@ func (l *lexer) next() (bool, error) {
continue continue
} }
if len(val) > 32 {
return false, fmt.Errorf("heredoc marker too long on line #%d: %s", l.line, string(val))
}
// after hitting a newline, we know that the heredoc marker // after hitting a newline, we know that the heredoc marker
// is the characters after the two << and the newline. // is the characters after the two << and the newline.
// we reset the val because the heredoc is syntax we don't // we reset the val because the heredoc is syntax we don't