Merge pull request #28575 from Luap99/container-inspect-json

fix container inspect output to not escape html chars
This commit is contained in:
Matt Heon authored and GitHub committed 2026-04-23 15:16:11 -04:00
commit 7bf32ef98b
2 files changed
+18 -2

No files matched your search

+9 -2
View File
@@ -1,6 +1,7 @@
package define
import (
"bytes"
"encoding/json"
"fmt"
"strings"
@@ -153,11 +154,16 @@ func (insp *InspectContainerConfig) UnmarshalJSON(data []byte) error {
}
func (insp *InspectContainerConfig) MarshalJSON() ([]byte, error) {
buf := bytes.Buffer{}
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)
// the alias is needed otherwise MarshalJSON will
type Alias InspectContainerConfig
conf := (*Alias)(insp)
if !insp.V4PodmanCompatMarshal {
return json.Marshal(conf)
err := enc.Encode(conf)
return buf.Bytes(), err
}
type v4InspectContainerConfig struct {
@@ -171,7 +177,8 @@ func (insp *InspectContainerConfig) MarshalJSON() ([]byte, error) {
StopSignal: uint(stopSignal),
Alias: conf,
}
return json.Marshal(newConf)
err := enc.Encode(newConf)
return buf.Bytes(), err
}
// InspectRestartPolicy holds information about the container's restart policy.
+9
View File
@@ -263,6 +263,15 @@ var _ = Describe("Podman inspect", func() {
Expect(baseJSON[0]).To(HaveField("Name", ctrName))
})
It("podman inspect should not escape special chars", func() {
ctrName := "testlabel"
podmanTest.PodmanExitCleanly("create", "--name", ctrName, "--label", "abc=&&**<>123", ALPINE, "sh")
// see https://github.com/containers/podman/issues/28560
inspect := podmanTest.PodmanExitCleanly("inspect", ctrName)
Expect(inspect.OutputToString()).To(ContainSubstring(`"abc=&&**<>123"`))
})
It("podman inspect - HostConfig.SecurityOpt ", func() {
if !selinux.GetEnabled() {
Skip("SELinux not enabled")