From abfe1e6180ec101a9d47427299caab40165dfff4 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 2 Aug 2025 16:41:24 +0200 Subject: [PATCH] apk: fix empty/whitespace-only package name check (#10532) * Fix empty/whitespace-only package name check. * Adjust test. --- changelogs/fragments/10532-apk.yml | 2 ++ plugins/modules/apk.py | 2 +- tests/integration/targets/apk/tasks/main.yml | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/10532-apk.yml diff --git a/changelogs/fragments/10532-apk.yml b/changelogs/fragments/10532-apk.yml new file mode 100644 index 0000000000..84c5d985e8 --- /dev/null +++ b/changelogs/fragments/10532-apk.yml @@ -0,0 +1,2 @@ +bugfixes: + - "apk - fix check for empty/whitespace-only package names (https://github.com/ansible-collections/community.general/pull/10532)." diff --git a/plugins/modules/apk.py b/plugins/modules/apk.py index 7ad5d5908e..e70e51a1f0 100644 --- a/plugins/modules/apk.py +++ b/plugins/modules/apk.py @@ -351,7 +351,7 @@ def main(): p = module.params - if all(not name.strip() for name in p['name']): + if p['name'] and any(not name.strip() for name in p['name']): module.fail_json(msg="Package name(s) cannot be empty or whitespace-only") if p['no_cache']: diff --git a/tests/integration/targets/apk/tasks/main.yml b/tests/integration/targets/apk/tasks/main.yml index c800b1fa1c..b8e0e2efbe 100644 --- a/tests/integration/targets/apk/tasks/main.yml +++ b/tests/integration/targets/apk/tasks/main.yml @@ -183,16 +183,17 @@ - result_spaces is failed - "'Package name(s) cannot be empty or whitespace-only' == result_spaces.msg" - - name: Accept list with valid and empty string + - name: Do not accept list with valid and empty string community.general.apk: name: ["busybox", ""] - register: result_valid_mixed + register: result_invalid_mixed ignore_errors: true - - name: Assert success with mixed package list + - name: Assert failure with mixed package list ansible.builtin.assert: that: - - result_valid_mixed is not failed + - result_invalid_mixed is failed + - "'Package name(s) cannot be empty or whitespace-only' == result_invalid_mixed.msg" - name: Reject package name list with multiple empty/whitespace-only strings community.general.apk: