Fix TypeError in split_args function#86352
Fix TypeError in split_args function#86352Nicole-Dev24 wants to merge 1 commit intoansible:develfrom
Conversation
|
The test The test |
|
Not sure if I missed your response to #86329 (comment), but what is the use case? |
|
#86329 (comment) as per my comment, I don't think that we should 'fix' this code, but either remove or consolidate the implementations |
|
I looked at usage of |
While studying the Ansible codebase to better understand it before contributing, this piece of code caught my attention... So I decided to investigate it a little further |
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