display - Replace CRNL with NL (#85194)

(cherry picked from commit e226294855)
pull/85255/head
Matt Clay 7 months ago committed by Matt Davis
parent 424327c293
commit 3207e55ca2

@ -0,0 +1,4 @@
minor_changes:
- display - Replace Windows newlines (``\r\n``) in display output with Unix newlines (``\n``).
This ensures proper display of strings sourced from Windows hosts in environments which treat ``\r`` as ``\n``,
such as Azure Pipelines.

@ -437,6 +437,10 @@ class Display(metaclass=Singleton):
if not isinstance(msg, str):
raise TypeError(f'Display message must be str, not: {msg.__class__.__name__}')
# Convert Windows newlines to Unix newlines.
# Some environments, such as Azure Pipelines, render `\r` as an additional `\n`.
msg = msg.replace('\r\n', '\n')
nocolor = msg
if not log_only:

@ -0,0 +1,3 @@
shippable/posix/group5
context/controller
gather_facts/no

@ -0,0 +1,13 @@
from __future__ import annotations
from ansible.module_utils.basic import AnsibleModule
def main() -> None:
m = AnsibleModule({})
m.warn("Hello\r\nNew\rAnsible\nWorld")
m.exit_json()
if __name__ == '__main__':
main()

@ -0,0 +1,10 @@
- name: Run a command which generates a warning with NL, CR and CRNL
command: ansible -m noisy localhost
register: result
environment:
ANSIBLE_FORCE_COLOR: 0
ANSIBLE_LIBRARY: "{{ role_path }}/library"
- name: Verify NL and CR are preserved, but CRNL is converted to NL
assert:
that: result.stderr is contains 'Hello\nNew\rAnsible\nWorld'
Loading…
Cancel
Save