Skip to content

Commit

Permalink
Revert "caddyfile: Reject long heredoc markers (#6098)" (#6100)
Browse files Browse the repository at this point in the history
This reverts commit e7a534d.
  • Loading branch information
mohammed90 authored Feb 12, 2024
1 parent f9e1115 commit 21744b6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 42 deletions.
5 changes: 0 additions & 5 deletions caddyconfig/caddyfile/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package caddyfile

import (
"bytes"
"fmt"
"io"
"unicode"

Expand Down Expand Up @@ -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
}
Expand Down
45 changes: 12 additions & 33 deletions caddyconfig/caddyfile/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package caddyfile

import (
"fmt"
"os"
"strings"
"testing"
)
Expand All @@ -26,7 +24,6 @@ func TestFormatter(t *testing.T) {
description string
input string
expect string
panics bool
}{
{
description: "very simple",
Expand Down Expand Up @@ -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))
}
}
}
4 changes: 0 additions & 4 deletions caddyconfig/caddyfile/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file not shown.

0 comments on commit 21744b6

Please sign in to comment.