From a1a624b150e5c621f6aee18f9b79b65c77dc02e7 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 27 Aug 2020 14:42:56 -0500 Subject: [PATCH] Normalize how None is handled in quote filter. Fixes #32174 (#71473) --- changelogs/fragments/32174-normalize-None-quote.yml | 3 +++ lib/ansible/plugins/filter/core.py | 2 ++ test/integration/targets/filter_core/tasks/main.yml | 7 +++++++ 3 files changed, 12 insertions(+) create mode 100644 changelogs/fragments/32174-normalize-None-quote.yml diff --git a/changelogs/fragments/32174-normalize-None-quote.yml b/changelogs/fragments/32174-normalize-None-quote.yml new file mode 100644 index 00000000000..f6a482646d5 --- /dev/null +++ b/changelogs/fragments/32174-normalize-None-quote.yml @@ -0,0 +1,3 @@ +bugfixes: +- quote filter - normalize how ``None`` is handled, to match Python3 behavior + (https://github.com/ansible/ansible/issues/32174) diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index f614c6560f8..591d3e8386e 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -110,6 +110,8 @@ def strftime(string_format, second=None): def quote(a): ''' return its argument quoted for shell usage ''' + if a is None: + a = u'' return shlex_quote(to_text(a)) diff --git a/test/integration/targets/filter_core/tasks/main.yml b/test/integration/targets/filter_core/tasks/main.yml index 6ef27d9dbe6..4a21f543d12 100644 --- a/test/integration/targets/filter_core/tasks/main.yml +++ b/test/integration/targets/filter_core/tasks/main.yml @@ -601,3 +601,10 @@ bar: 123 thing_items: '{{ thing_dict.items() }}' thing_range: '{{ range(10) }}' + +- name: Assert that quote works on None + assert: + that: + - thing|quote == "''" + vars: + thing: null