fix --format {{json .}} output to match docker

`--format json` should not be the same as `--format {{json .}}`, the
later should actually run through the go template and thus create one
json object per entry instead of an json array.

Includes a vendor of c/common@main since it requires a fix from there as
well.

This matches docker compat.
Fixes #16436

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2022-11-08 14:28:33 +01:00
parent 919678d2f8
commit 3e08f85353
26 changed files with 433 additions and 118 deletions

View File

@@ -1,8 +1,12 @@
package report
import "regexp"
import (
"regexp"
)
var jsonRegex = regexp.MustCompile(`^\s*(json|{{\s*json\s*(\.)?\s*}})\s*$`)
// Check for json, {{json }} and {{ json. }} which are not valid go template,
// {{json .}} is valid and thus not matched to let the template handle it like docker does.
var jsonRegex = regexp.MustCompile(`^\s*(json|{{\s*json\.?\s*}})\s*$`)
// JSONFormat test CLI --format string to be a JSON request
//