Skip to content

Commit

Permalink
Make quote_plus behave the same on Python 2 and 3. (#838)
Browse files Browse the repository at this point in the history
The tilde behavior was changed between 2 and 3; this also bit us in
another issue, see #783.
  • Loading branch information
houglum authored Jun 28, 2019
1 parent aba51e9 commit 0cf2f32
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gslib/commands/rsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def _EncodeUrl(url_string):
# in Python 2 or `bytes` in Python 3, it leads to surprising behavior for text
# containing unicode chars.
url_string = six.ensure_str(url_string)
return urllib.parse.quote_plus(url_string)
return urllib.parse.quote_plus(url_string, safe=b'~')


def _DecodeUrl(enc_url_string):
Expand Down
2 changes: 1 addition & 1 deletion gslib/tests/test_rsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def testUrlEncodeAndDecode(self):
# Test special URL chars as well as unicode:
decoded_url = 'gs://bkt/space fslash/plus+tilde~unicodeeè'
encoded_url = (
'gs%3A%2F%2Fbkt%2Fspace+fslash%2Fplus%2Btilde%7Eunicodee%C3%A8')
'gs%3A%2F%2Fbkt%2Fspace+fslash%2Fplus%2Btilde~unicodee%C3%A8')

# Encode accepts unicode, returns language-appropriate string type.
self.assertEqual(rsync._EncodeUrl(six.ensure_text(decoded_url)),
Expand Down

0 comments on commit 0cf2f32

Please sign in to comment.