From 9faf94468bd2e2b622908865d8e67d8dfdfccbd5 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 28 Mar 2023 10:41:02 -0500 Subject: [PATCH] Enforce that `Display.display` requires a `str` (#80327) * Enforce that Display.display requires a str * clog frag * ci_complete --- changelogs/fragments/display-display-str-only.yml | 2 ++ lib/ansible/utils/display.py | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 changelogs/fragments/display-display-str-only.yml diff --git a/changelogs/fragments/display-display-str-only.yml b/changelogs/fragments/display-display-str-only.yml new file mode 100644 index 00000000000..af3061098f4 --- /dev/null +++ b/changelogs/fragments/display-display-str-only.yml @@ -0,0 +1,2 @@ +bugfixes: +- Perform type check on data passed to Display.display to enforce the requirement of being given a python3 unicode string diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py index 16966aaf0d7..b4ff01c0060 100644 --- a/lib/ansible/utils/display.py +++ b/lib/ansible/utils/display.py @@ -326,6 +326,9 @@ class Display(metaclass=Singleton): Note: msg *must* be a unicode string to prevent UnicodeError tracebacks. """ + if not isinstance(msg, str): + raise TypeError(f'Display message must be str, not: {msg.__class__.__name__}') + if self._final_q: # If _final_q is set, that means we are in a WorkerProcess # and instead of displaying messages directly from the fork