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

newline characters are not printed out as newlines when binary text output is used in an OutputTemplate #306

Closed
reubenmiller opened this issue Sep 7, 2023 · 0 comments · Fixed by #371
Labels
bug Something isn't working

Comments

@reubenmiller
Copy link
Owner

reubenmiller commented Sep 7, 2023

There seems to be some encoding issues when handing non-json text output inside an output template.

When an output template is not used, the following writes to the console with literal newlines (not the \n character).

 c8y events list --type c8y-configuration-plugin \
| c8y events downloadBinary --noProgress --outputTemplate "response.body"

Output

# Add the configurations to be managed by c8y-configuration-plugin
files = [
#    { path = '/etc/tedge/tedge.toml' },
#    { path = '/etc/tedge/mosquitto-conf/c8y-bridge.conf', type = 'c8y-bridge.conf' },
#    { path = '/etc/tedge/mosquitto-conf/tedge-mosquitto.conf', type = 'tedge-mosquitto.conf' },
#    { path = '/etc/mosquitto/mosquitto.conf', type = 'mosquitto.conf' },
#    { path = '/etc/tedge/c8y/example.txt', type = 'example', user = 'tedge', group = 'tedge', mode = 0o444 }
]

However when using a custom output template which should do the same thing,

c8y events list -p 1 --type c8y-configuration-plugin \
| c8y events downloadBinary --noProgress --outputTemplate "response.body"

Output

# Add the configurations to be managed by c8y-configuration-plugin\nfiles = [\n#    { path = '/etc/tedge/tedge.toml' },\n#    { path = '/etc/tedge/mosquitto-conf/c8y-bridge.conf', type = 'c8y-bridge.conf' },\n#    { path = '/etc/tedge/mosquitto-conf/tedge-mosquitto.conf', type = 'tedge-mosquitto.conf' },\n#    { path = '/etc/mosquitto/mosquitto.conf', type = 'mosquitto.conf' },\n#    { path = '/etc/tedge/c8y/example.txt', type = 'example', user = 'tedge', group = 'tedge', mode = 0o444 }\n]

Workaround

You can use sed to do the replacement of \n with a literal newline:

c8y events list -p 1 --type c8y-configuration-plugin \
| c8y events downloadBinary --noProgress --outputTemplate "'\n\n# Device: ' + request.url + '\n' + output + '\n'" \
| sed 's|\\n|\n|g'

Output



# Device: https://example.c8y.io/event/events/3505464/binaries
# Add the configurations to be managed by c8y-configuration-plugin
files = [
#    { path = '/etc/tedge/tedge.toml' },
#    { path = '/etc/tedge/mosquitto-conf/c8y-bridge.conf', type = 'c8y-bridge.conf' },
#    { path = '/etc/tedge/mosquitto-conf/tedge-mosquitto.conf', type = 'tedge-mosquitto.conf' },
#    { path = '/etc/mosquitto/mosquitto.conf', type = 'mosquitto.conf' },
#    { path = '/etc/tedge/c8y/example.txt', type = 'example', user = 'tedge', group = 'tedge', mode = 0o444 }
]
@reubenmiller reubenmiller added the bug Something isn't working label Sep 7, 2023
reubenmiller added a commit that referenced this issue May 18, 2024
@reubenmiller reubenmiller linked a pull request May 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant