Skip to content

Commit

Permalink
Fix url parsing for S3 (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
rileypeterson authored and menshikh-iv committed Sep 24, 2018
1 parent a971d06 commit efb74ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions smart_open/smart_open_lib.py
Expand Up @@ -84,7 +84,7 @@


Uri = collections.namedtuple(
'Uri',
'Uri',
(
'scheme',
'uri_path',
Expand Down Expand Up @@ -488,7 +488,7 @@ def _parse_uri_s3x(parsed_uri):
try:
uri = parsed_uri.netloc + parsed_uri.path
# Separate authentication from URI if exist
if ':' in uri.split('@')[0]:
if ':' in uri.split('@')[0] and '@' in uri:
auth, uri = uri.split('@', 1)
access_id, access_secret = auth.split(':')
else:
Expand Down
9 changes: 9 additions & 0 deletions smart_open/tests/test_smart_open.py
Expand Up @@ -128,6 +128,15 @@ def test_uri_from_issue_223_works(self):
self.assertEqual(parsed_uri.access_id, "")
self.assertEqual(parsed_uri.access_secret, "")

def test_s3_uri_with_colon_in_key_name(self):
""" Correctly parse the s3 url if there is a colon in the key or dir """
parsed_uri = smart_open_lib._parse_uri("s3://mybucket/mydir/my:key")
self.assertEqual(parsed_uri.scheme, "s3")
self.assertEqual(parsed_uri.bucket_id, "mybucket")
self.assertEqual(parsed_uri.key_id, "mydir/my:key")
self.assertEqual(parsed_uri.access_id, None)
self.assertEqual(parsed_uri.access_secret, None)


class SmartOpenHttpTest(unittest.TestCase):
"""
Expand Down

0 comments on commit efb74ce

Please sign in to comment.