Fix TypeError in split_args function #86352
Open
+34
−39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.pyand 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