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

The 'cat << EOF' produces wrong output when using escaped quotes #1538

Open
ninlil opened this issue Mar 7, 2024 · 1 comment
Open

The 'cat << EOF' produces wrong output when using escaped quotes #1538

ninlil opened this issue Mar 7, 2024 · 1 comment
Labels
dep: mvdan/sh Issues related to the upstream interpreter used by Task. type: bug Something not working as intended.

Comments

@ninlil
Copy link

ninlil commented Mar 7, 2024

  • Task version: v3.35.1
  • Operating system: Ubuntu 20.04
  • Experiments enabled: none

Basic shell command works exactly the same in sh, bash and zsh (i.e producing the exact same output as input)

$ cat << EOF
{
  "key1": "a simple text with an escaped doublequote \" in the text"
}
EOF
{
  "key1": "a simple text with an escaped doublequote \" in the text"
}

but the following task prints different outputs:

version: '3'
tasks:
  test:
    vars:
      TEXT: |
        {
          "key1": "a simple text with an escaped doublequote \" in the text"
        }
    cmds:
      - echo '{{.TEXT}}'
      - |
        cat << EOF
        {{.TEXT}}
        EOF

Output: (do note the last entry not having an escaped doublequote)

$ task test
task: [test] echo '{
  "key1": "a simple text with an escaped doublequote \" in the text"
}
'
{
  "key1": "a simple text with an escaped doublequote \" in the text"
}

task: [test] cat << EOF
{
  "key1": "a simple text with an escaped doublequote \" in the text"
}

EOF

{
  "key1": "a simple text with an escaped doublequote " in the text"
}

I see this as 1 bug and 1 feature-request:

feature suggestion: apart of settings your command using the "sh:" key, add a "stdin" or "input" key to be a variable

    cmds:
      - sh: cat
        stdin: TEXT
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Mar 7, 2024
@ninlil ninlil changed the title The 'cat << EOF' fails when using escaped quotes The 'cat << EOF' produces wrong output when using escaped quotes Mar 7, 2024
@mochja
Copy link

mochja commented Apr 10, 2024

@ninlil this indeed seems to be a bug in the upstream gosh project. I am going to open a bug report there.

gosh
$ cat << EOF
> test \" test
> EOF
test " test
bash
bash-3.2$ cat << EOF
> test \" test
> EOF
test \" test
bash-3.2$

You can workaround the issue using here-string cat <<< {{.TEXT | shellQuote}}, which produce:

task: [test] cat <<< $'{\n  "key1": "a simple text with an escaped doublequote \\" in the text"\n}\n'
{
  "key1": "a simple text with an escaped doublequote \" in the text"
}

@pd93 pd93 added type: bug Something not working as intended. dep: mvdan/sh Issues related to the upstream interpreter used by Task. and removed state: needs triage Waiting to be triaged by a maintainer. labels Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dep: mvdan/sh Issues related to the upstream interpreter used by Task. type: bug Something not working as intended.
Projects
None yet
Development

No branches or pull requests

4 participants