Skip to content

Broken json format for version subcommad #9236

@victor-timofei

Description

@victor-timofei

Description

Steps to reproduce the issue:

./bin/docker-compose version -f json

Describe the results you received:
{"version":"v2.3.0-2-gfcff3963"}\n
The newline character was not escaped properly

Describe the results you expected:
{"version":"v2.3.0-2-gfcff3963"}
With a newline.

Additional information you deem important (e.g. issue happens only occasionally):
The json format is printed with:

fmt.Printf(`{"version":%q}\n`, internal.Version)

I think we should either use double-quotes and escape the inner quotes, instead of backticks because the newline is not escaped properly.

fmt.Printf("{\"version\":%q}\n", internal.Version)

Or add a newline character after the closing curly bracket like:

fmt.Printf(`{"version":%q}
`, internal.Version)

I think the better option would be the first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions