Skip to content

Conversation

@Nicole-Dev24
Copy link

SUMMARY

The split_args() function in ansible.module_utils.splitter crashes with a TypeError when processing normal string input in Python 3, due to the function attempting to split byte encoded strings using string delimiters. More specifically, the function originally encoded string input to bytes and then performed split operations on the bytes object using string delimiters (e.g., '\n' and ' '), causing a TypeError.

To fix the issue, if the input is a bytes object, it should be first decoded to a string before processing; thus, this matches the behavior of a similar function in ansible/parsing/splitter.py and ensures Python 3 compatibility. That is why I removed the args.encode('utf-8') and args.decode() logic, and added a check for byte input and decode it to a string if necessary using UTF-8 or Latin-1 encoding.

Fixes #86329 (Obs: discussions are still being made by the Ansible community in this issue).

ISSUE TYPE
  • Bugfix Pull Request

@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. has_issue needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 17, 2025
@ansibot
Copy link
Contributor

ansibot commented Dec 17, 2025

The test ansible-test sanity --test pep8 [explain] failed with 9 errors:

lib/ansible/module_utils/splitter.py:83:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:90:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:93:29: W291: trailing whitespace
lib/ansible/module_utils/splitter.py:101:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:115:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:137:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:188:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:202:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:205:1: E303: too many blank lines (3)

The test ansible-test sanity --test pylint [explain] failed with 8 errors:

lib/ansible/module_utils/splitter.py:83:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:90:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:93:28: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:101:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:115:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:137:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:188:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:202:0: trailing-whitespace: Trailing whitespace

click here for bot help

@s-hertel
Copy link
Contributor

Not sure if I missed your response to #86329 (comment), but what is the use case?

@bcoca
Copy link
Member

bcoca commented Dec 17, 2025

#86329 (comment) as per my comment, I don't think that we should 'fix' this code, but either remove or consolidate the implementations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue/PR relates to a bug. has_issue needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_triage Needs a first human triage before being processed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

split_args() fails due to bytes and str type mismatch

4 participants