mirror of
https://github.com/ansible/ansible.git
synced 2026-07-28 16:15:12 +02:00
display - Replace CRNL with NL (#85194)
This commit is contained in:
@@ -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'
|
||||
Reference in New Issue
Block a user