Browse code

Make run_command() work when we get byte str with non-ascii characters (instead of unicode type like we were expecting)

Fix and test.

Fixes #10536

Toshio Kuratomi authored on 2015/03/26 04:22:45
Showing 2 changed files
... ...
@@ -1457,7 +1457,12 @@ class AnsibleModule(object):
1457 1457
         # in reporting later, which strips out things like
1458 1458
         # passwords from the args list
1459 1459
         if isinstance(args, basestring):
1460
-            to_clean_args = shlex.split(args.encode('utf-8'))
1460
+            if isinstance(args, unicode):
1461
+                b_args = args.encode('utf-8')
1462
+            else:
1463
+                b_args = args
1464
+            to_clean_args = shlex.split(b_args)
1465
+            del b_args
1461 1466
         else:
1462 1467
             to_clean_args = args
1463 1468
 
... ...
@@ -41,6 +41,15 @@
41 41
     - name: 'A task with unicode host vars'
42 42
       debug: var=unicode_host_var
43 43
 
44
+    - name: 'A task with unicode shell parameters'
45
+      shell: echo '¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö ×'
46
+      register: output
47
+
48
+    - name: 'Assert that the unicode was echoed'
49
+      assert:
50
+        that:
51
+          - "'¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö ×' in output.stdout_lines"
52
+
44 53
 - name: 'A play for hosts in group: ĪīĬĭ'
45 54
   hosts: 'ĪīĬĭ'
46 55
   gather_facts: true