Skip to content

Commit

Permalink
Fix the combination of "table " and \n in report formats
Browse files Browse the repository at this point in the history
Completely skipping the NormalizeFormat part also skipped the
removal of the "table " directive.

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Feb 22, 2023
1 parent fde0ca9 commit 8475920
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/report/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ func (f *Formatter) Parse(origin Origin, text string) (*Formatter, error) {
// parse the template. If it fails use the original text and parse again.
var normText string
switch {
case strings.HasPrefix(text, "table "):
case strings.HasPrefix(text, "table "): // This could use strings.CutPrefix after we require Go 1.20
f.RenderTable = true
normText = "{{range .}}" + NormalizeFormat(text) + "{{end -}}"
text = "{{range .}}" + text + "{{end -}}"
text = "{{range .}}" + text[len("table "):] + "{{end -}}"
case OriginUser == origin:
normText = EnforceRange(NormalizeFormat(text))
text = EnforceRange(text)
Expand Down
1 change: 1 addition & 0 deletions pkg/report/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestFormatter_ParseTable(t *testing.T) {
{&bytes.Buffer{}, OriginUser, `{{range .}}{{.ID}}{{end -}}`, "c061a0839ef10fc2e110571eb6fab5aa8f4b5cbfd3e66aa35e9b2a"},
// regression test for https://bugzilla.redhat.com/show_bug.cgi?id=2059658 and https://github.com/containers/podman/issues/13446
{&bytes.Buffer{}, OriginUser, `{{range .}}{{printf "\n"}}{{end -}}`, "\n\n\n"},
{&tabwriter.Writer{}, OriginUser, `table {{printf "\n"}}`, "\n\n\n\n"},
}

for loop, tc := range testCase {
Expand Down

0 comments on commit 8475920

Please sign in to comment.