diff options
author | Mohammed Al Sahaf <[email protected]> | 2024-02-12 21:06:22 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2024-02-12 18:06:22 +0000 |
commit | 21744b6c4cabbdeaa81f645c3068c92dffa856e0 (patch) | |
tree | ae9ee141dab039ef8d0e7a7d168b81b443a1a8a5 | |
parent | f9e11158bc139294804cba99e9fea408f1fb00d6 (diff) | |
download | caddy-21744b6c4cabbdeaa81f645c3068c92dffa856e0.tar.gz caddy-21744b6c4cabbdeaa81f645c3068c92dffa856e0.zip |
Revert "caddyfile: Reject long heredoc markers (#6098)" (#6100)
This reverts commit e7a534d0a311d9fa75b5981879c755281c4c9fba.
-rw-r--r-- | caddyconfig/caddyfile/formatter.go | 5 | ||||
-rw-r--r-- | caddyconfig/caddyfile/formatter_test.go | 45 | ||||
-rw-r--r-- | caddyconfig/caddyfile/lexer.go | 4 | ||||
-rw-r--r-- | caddyconfig/caddyfile/testdata/clusterfuzz-testcase-minimized-fuzz-format-5806400649363456 | bin | 139348 -> 0 bytes |
4 files changed, 12 insertions, 42 deletions
diff --git a/caddyconfig/caddyfile/formatter.go b/caddyconfig/caddyfile/formatter.go index 423de542a..764f79118 100644 --- a/caddyconfig/caddyfile/formatter.go +++ b/caddyconfig/caddyfile/formatter.go @@ -16,7 +16,6 @@ package caddyfile import ( "bytes" - "fmt" "io" "unicode" @@ -119,10 +118,6 @@ func Format(input []byte) []byte { heredoc = heredocClosed } else { heredocMarker = append(heredocMarker, ch) - if len(heredocMarker) > 32 { - errorString := fmt.Sprintf("heredoc marker too long: <<%s", string(heredocMarker)) - panic(errorString) - } write(ch) continue } diff --git a/caddyconfig/caddyfile/formatter_test.go b/caddyconfig/caddyfile/formatter_test.go index 5ea29c335..6eec822fe 100644 --- a/caddyconfig/caddyfile/formatter_test.go +++ b/caddyconfig/caddyfile/formatter_test.go @@ -15,8 +15,6 @@ package caddyfile import ( - "fmt" - "os" "strings" "testing" ) @@ -26,7 +24,6 @@ func TestFormatter(t *testing.T) { description string input string expect string - panics bool }{ { 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) { - if tc.panics { - defer func() { - if r := recover(); r == nil { - t.Errorf("[TEST %d: %s] Expected panic, but got none", i, tc.description) - } - }() - } - - // the formatter should output a trailing newline, - // 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 !tc.panics && string(actual) != tc.expect { - t.Errorf("\n[TEST %d: %s]\n====== EXPECTED ======\n%s\n====== ACTUAL ======\n%s^^^^^^^^^^^^^^^^^^^^^", - i, tc.description, string(tc.expect), string(actual)) - } - }) + // the formatter should output a trailing newline, + // 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^^^^^^^^^^^^^^^^^^^^^", + i, tc.description, string(tc.expect), string(actual)) + } } } diff --git a/caddyconfig/caddyfile/lexer.go b/caddyconfig/caddyfile/lexer.go index a59f0fc46..4db63749b 100644 --- a/caddyconfig/caddyfile/lexer.go +++ b/caddyconfig/caddyfile/lexer.go @@ -149,10 +149,6 @@ func (l *lexer) next() (bool, error) { 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 // is the characters after the two << and the newline. // we reset the val because the heredoc is syntax we don't diff --git a/caddyconfig/caddyfile/testdata/clusterfuzz-testcase-minimized-fuzz-format-5806400649363456 b/caddyconfig/caddyfile/testdata/clusterfuzz-testcase-minimized-fuzz-format-5806400649363456 Binary files differdeleted file mode 100644 index 94b70919c..000000000 --- a/caddyconfig/caddyfile/testdata/clusterfuzz-testcase-minimized-fuzz-format-5806400649363456 +++ /dev/null |