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

Regression: "unterminated quoted string" using escape sequences in inspect template #13446

Closed
owtaylor opened this issue Mar 7, 2022 · 14 comments · Fixed by #15673
Closed

Regression: "unterminated quoted string" using escape sequences in inspect template #13446

owtaylor opened this issue Mar 7, 2022 · 14 comments · Fixed by #15673
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@owtaylor
Copy link

owtaylor commented Mar 7, 2022

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

Steps to reproduce the issue:

  1. `podman pull registry.access.redhat.com/ubi8'

  2. podman inspect registry.access.redhat.com/ubi8 --format='{{ range .Config.Env }}{{ . }}{{"\n"}}{{ end }}'

Describe the results you received:

ERRO[0000] Printing inspect output: template: all inspect:1: unterminated quoted string

Describe the results you expected:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
container=oci

Additional information you deem important (e.g. issue happens only occasionally):

  • Works fine with "podman version 3.4.4"

  • The example above isn't minimal - podman info -f '{{ "hello world\n" }}' will reproduce too. But showing it as a more realistic example.

  • A workaround is to use {{ println . }} instead of {{ . }}{{ "\n" }}

  • See Unterminated quoted string bug owtaylor/toolbox-vscode#21

Output of podman version:

podman version 4.0.0-rc4

Output of podman info --debug:

[ omitted for readability, if this isn't obviously reproducible, I will provide ]

Package info (e.g. output of rpm -q podman or apt list podman):

podman-4.0.0-0.6.rc4.fc36.x86_64

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)

Yes

@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Mar 7, 2022
@mheon
Copy link
Member

mheon commented Mar 7, 2022

@jwhonce PTAL

owtaylor pushed a commit to owtaylor/toolbox-vscode that referenced this issue Mar 9, 2022
Release candidates of podman v4 are unable to handle escape sequences inside strings.
See: containers/podman#13446
Work around this by using the println function instead.
@flouthoc
Copy link
Collaborator

Hi @owtaylor I think this change was intentionally added here containers/common#831 so \n can be replaced with actual breakline when used in format string.

Your use-case is already documented here in tests: containers/common#831

So something like this should work
podman inspect registry.access.redhat.com/ubi8 --format='{{ range .Config.Env }}{{ . }}\n{{ end }}'
or
podman inspect registry.access.redhat.com/ubi8 --format='{{ range .Config.Env }}{{ . }}{{`\n`}}{{ end }}'

I'm closing this issue but feel free to re-open.

@owtaylor
Copy link
Author

OK, dug into this some, and I believe that the situation is:

  • podman < 4: \t is replaced with a literal tab for all templates
  • docker cli: \t is replaced with a literal tab, \n is replaced with a literal newline for many template arguments (ps, images, etc), no replacements are done for other templates (inspect, info). With the dividing line being, as I understand it, the templates where the table keyword can be used to get tabular output for a list of objects.
  • podman 4: \t is replaced with a literal tab, \n is replaced with a literal newline for all templates

So we see that the behavior of podman inspect in podman 4 matches neither the behavior of podman < 4 or the behavior of docker inspect. The example I provided works fine with docker inspect.

I can see where the docker behavior where different --format= arguments are treated differently could be considered a bit wonky. But it seems that, for the case of inspect, that an incompatible change that is being made to increase compatibility with the docker CLI is making things less compatible with the docker CLI?

@flouthoc
Copy link
Collaborator

flouthoc commented Mar 22, 2022

I think for consistency --format of all the options should match but if docker inspect is being treated as anomaly then I think we should also do this, but since changes in containers/common#831 seemed intentional so I'll request @jwhonce to take a look.

I'll also re-open this issue since this needs more clarification.

@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Apr 22, 2022

@flouthoc Lets match docker inspect.

@flouthoc
Copy link
Collaborator

flouthoc commented Apr 22, 2022

#13446 (comment)

but since changes in containers/common#831 seemed intentional so I'll request @jwhonce to take a look.

@rhatdan I was not entirely sure about the above PR and changed seemed intentional hence requested @jwhonce to take a look.

@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Jun 27, 2022

@flouthoc since we never heard word back from @jwhonce lets fix it to match inspect.

@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

Luap99 added a commit to Luap99/common that referenced this issue 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 lof 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]>
Luap99 added a commit to Luap99/common that referenced this issue 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.

Signed-off-by: Paul Holzinger <[email protected]>
Luap99 added a commit to Luap99/libpod that referenced this issue Sep 7, 2022
This includes a fix for the go template parsing to allow `\n` in
template strings.

Fixes containers#13446
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2059658

Signed-off-by: Paul Holzinger <[email protected]>
@in-fke
Copy link

in-fke commented Mar 29, 2023

why does this does not work?

podman inspect --format='{{join .HostConfig.Binds "\n"}}' container
ERRO[0000] Printing inspect output: template: all inspect:1: unterminated quoted string
podman --version
podman version 4.2.0

@Luap99
Copy link
Member

Luap99 commented Mar 29, 2023

Because this was fixed in v4.3

@in-fke
Copy link

in-fke commented Mar 30, 2023

Because this was fixed in v4.3

Thanks for the quick reply - I am still struggling finding out which GitHub Issue actually fixed in which version / tag / branch.

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Aug 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants