Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/report: handle newline in template string #1146

Merged
merged 1 commit into from
Sep 6, 2022

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented Sep 6, 2022

Docker tries to be smart and replaces \n with the actual newline character.
For compat we do the same but this will break formats such as '{{printf "\n"}}'
To be backwards compatible with the previous behavior we try to replace and
parse the template. If it fails use the original text and parse again.

This fix will not be enough. It requires many changes in podman since
most commands will do their own NormalizeFormat() call before using this
backend which seems wrong and creates a lot of duplication. This has to
be fixed in Podman.

Required for https://bugzilla.redhat.com/show_bug.cgi?id=2059658
and containers/podman#13446.

Docker tries to be smart and replaces \n with the actual newline character.
For compat we do the same but this will break formats such as '{{printf "\n"}}'
To be backwards compatible with the previous behavior we try to replace and
parse the template. If it fails use the original text and parse again.

This fix will not be enough. It requires many changes in podman since
most commands will do their own NormalizeFormat() call before using this
backend which seems wrong and creates a lot of duplication. This has to
be fixed in Podman.

Required for https://bugzilla.redhat.com/show_bug.cgi?id=2059658
and containers/podman#13446.

Signed-off-by: Paul Holzinger <[email protected]>
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 6, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Sep 6, 2022
Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rhatdan
Copy link
Member

rhatdan commented Sep 6, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Sep 6, 2022
@openshift-merge-robot openshift-merge-robot merged commit 0fe9ce2 into containers:main Sep 6, 2022
@Luap99 Luap99 deleted the template branch September 6, 2022 13:36
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 7, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 7, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 7, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

Also fix a bug where a invlaid template would not cause a exit code > 0,
see the added test case.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 7, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 7, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 7, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 7, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 7, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

Also fix a bug where a invlaid template would not cause a exit code > 0,
see the added test case.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

Also fixa bug since the table format is expected to print headers as
well.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output, we can add a new test for the
newline bug when the common PR is vendored in.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this pull request Sep 13, 2022
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.

I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.

This change does not change the output.

[1] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants