Skip to content

Commit

Permalink
Encode dubious strings
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Jul 31, 2017
1 parent 4b29c7c commit 80b0a5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions awscli/customizations/s3/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from s3transfer.exceptions import FatalError
from s3transfer.subscribers import BaseSubscriber

from awscli.compat import queue, six
from awscli.compat import queue, ensure_text_type
from awscli.customizations.s3.utils import relative_path
from awscli.customizations.s3.utils import human_readable_size
from awscli.customizations.utils import uni_print
Expand Down Expand Up @@ -246,8 +246,11 @@ def _get_ongoing_dict_key(self, result):
'Any result using _get_ongoing_dict_key must subclass from '
'BaseResult. Provided result is of type: %s' % type(result)
)
properties = [result.transfer_type, result.src, result.dest]
return u':'.join(six.text_type(p) for p in properties)
key_parts = []
for result_property in [result.transfer_type, result.src, result.dest]:
if result_property is not None:
key_parts.append(ensure_text_type(result_property))
return u':'.join(key_parts)

def _pop_result_from_ongoing_dicts(self, result):
ongoing_key = self._get_ongoing_dict_key(result)
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/customizations/s3/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,20 @@ def test_result_with_unicode(self):
)
self.assertEqual(self.result_recorder.expected_files_transferred, 1)

def test_result_with_encoded_unicode(self):
unicode_source = u'\u2713'.encode('utf-8')
self.result_recorder(
QueuedResult(
transfer_type=self.transfer_type, src=unicode_source,
dest=self.dest, total_transfer_size=self.total_transfer_size
)
)
self.assertEqual(
self.result_recorder.expected_bytes_transferred,
self.total_transfer_size
)
self.assertEqual(self.result_recorder.expected_files_transferred, 1)


class BaseResultPrinterTest(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 80b0a5f

Please sign in to comment.