containers / skopeo

Work with remote images registries - retrieving information, images, signing content
Apache License 2.0
8.08k stars 766 forks source link

unicode character code shows in inspect #473

Closed gouyang closed 5 years ago

gouyang commented 6 years ago

\u003 and \u003e shows in inspect command.

# skopeo inspect containers-storage:docker.io/nginx
{
    "Digest": "sha256:926b086e1234b6ae9a11589c4cece66b267890d24d1da388c96dd8795b2ffcfb",
    "RepoTags": [],
    "Created": "2017-12-26T18:17:01.106799157Z",
    "DockerVersion": "17.06.2-ce",
    "Labels": {
        "maintainer": "NGINX Docker Maintainers \u003cdocker-maint@nginx.com\u003e"
    },
    "Architecture": "amd64",
    "Os": "linux",
    "Layers": [
        "sha256:e7bb522d92ff6d4e5b2087409b0fc783c2e3b06acf87bee739ee47d90bf02e96",
        "sha256:6edc05228666c8ac9ec17c7dbbd8477c1a68e5569ce9f917d3cf47574ba4633f",
        "sha256:cd866a17e81f2cadc87299bd322d025c29adca05d47651a3b15f89cd94c35b8d"
    ]
}
mtrmac commented 6 years ago

Thanks for the report. It’s actually \u003c and \u003e, escape sequences for < and >. This is a behavior of Golang json.Marshal, per https://golang.org/pkg/encoding/json/:

The angle brackets "<" and ">" are escaped to "\u003c" and "\u003e" to keep some browsers from misinterpreting JSON output as HTML.

Using raw </> and escaped \u003c/\u003e is semantically equivalent, and all JSON consumers should handle the two variants equivalently. Yes, it can look confusing to a human reader.

FWIW skopeo inspect … | python -mjson.tool can be used to remove the escapes because json.tool seems to not escape these characters, at least not by default.

We could also (@runcom ?) configure the marshaller in skopeo inspect with SetEscapeHTML(false), but if we are serious about using JSON, at least the " and \ characters certainly need to be escaped, so we can’t get completely human-readable output either way. For that, we would need to build a GUI which delineates fields using outlines and shading instead of text (and even then we could have serious difficulties due to e.g. right-to-left/left-to-right override control characters).

gouyang commented 6 years ago

@mtrmac There is similar issue in project buildah, it's solved in https://github.com/projectatomic/buildah/pull/421, for your reference.

mtrmac commented 6 years ago

I don’t really see this as valuable—to an extent, it’s better if human readers are reminded that this is JSON syntax and escapes matter—but I’ll defer to @runcom .

mtrmac commented 6 years ago

(Thanks for the pointer to working code, though.)

runcom commented 6 years ago

I don’t really see this as valuable—to an extent, it’s better if human readers are reminded that this is JSON syntax and escapes matter—but I’ll defer to @runcom .

I'd leave this is, it's JSON and maybe someone pipe that to a file

rhatdan commented 6 years ago

If they pipe to a file or to anything other then a TTY it will not change. It is only being done when Humans are looking at it.

mtrmac commented 5 years ago

That’s how it works in buildah, not in skopeo; anyway, the consensus seems to have been not to disable the escaping.