Merge pull request #27060 from yongtang/27021-inspect-show-env

Disable HTML escaping for JSON strings in `docker inspect`
This commit is contained in:
Vincent Demeester 2016-10-02 14:32:56 +02:00 коммит произвёл GitHub
Родитель 762556c705 0fa20ad13b
Коммит 420e22fad4
2 изменённых файлов: 13 добавлений и 1 удалений

Просмотреть файл

@ -81,7 +81,9 @@ func ParseForm(r *http.Request) error {
func WriteJSON(w http.ResponseWriter, code int, v interface{}) error { func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code) w.WriteHeader(code)
return json.NewEncoder(w).Encode(v) enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
return enc.Encode(v)
} }
// VersionFromContext returns an API version from the context using APIVersionKey. // VersionFromContext returns an API version from the context using APIVersionKey.

Просмотреть файл

@ -407,3 +407,13 @@ func (s *DockerSuite) TestInspectRootFS(c *check.C) {
c.Assert(len(imageJSON[0].RootFS.Layers), checker.GreaterOrEqualThan, 1) c.Assert(len(imageJSON[0].RootFS.Layers), checker.GreaterOrEqualThan, 1)
} }
func (s *DockerSuite) TestInspectAmpersand(c *check.C) {
testRequires(c, DaemonIsLinux)
name := "test"
out, _ := dockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env")
c.Assert(out, checker.Contains, `soanni&rtr`)
out, _ = dockerCmd(c, "inspect", name)
c.Assert(out, checker.Contains, `soanni&rtr`)
}