ansible-vault: add newline to the output of the 'encrypt_string' command (#79017)

* ansible-vault: add newline to the output of the 'encrypt_string' command

* Add comment with issue description and improve string joining

* Add changelog fragment

* Update changelogs/fragments/79017-ansible-vault-string-encryption-ending-with-newline.yml

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>

* Fixed some typos in changelog fragment

* Improve comment regarding newline character at the end of file

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
pull/79019/head^2
Dmytro Khomutnyk 2 years ago committed by GitHub
parent 56285b1d2b
commit b5db71e318
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,6 @@
bugfixes:
- >-
ansible-vault encrypt_string - started appending a line feed at the end of the encrypted string output. Missing newline
character caused problems identifying where the string ends in some shells (like bash) or accidentally copying an
extra trailing terminator symbol (e.g., zsh prints out a ``%`` sign to signal where the original output stops)
(https://github.com/ansible/ansible/issues/78932).

@ -384,6 +384,11 @@ class VaultCLI(CLI):
sys.stderr.write(err)
b_outs.append(to_bytes(out))
# The output must end with a newline to play nice with terminal representation.
# Refs:
# * https://stackoverflow.com/a/729795/595220
# * https://github.com/ansible/ansible/issues/78932
b_outs.append(b'')
self.editor.write_data(b'\n'.join(b_outs), context.CLIARGS['output_file'] or '-')
if sys.stdout.isatty():

Loading…
Cancel
Save