Skip to content

Commit

Permalink
Ensure that base64-encoded bytes get decoded to text for JSON. (#3195)
Browse files Browse the repository at this point in the history
Closes #3193.
  • Loading branch information
tseaver authored and lukesneeringer committed Mar 23, 2017
1 parent b035bf7 commit 5425bc7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bigquery/google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _bool_to_json(value):
def _bytes_to_json(value):
"""Coerce 'value' to an JSON-compatible representation."""
if isinstance(value, bytes):
value = base64.standard_b64encode(value)
value = base64.standard_b64encode(value).decode('ascii')
return value


Expand Down
7 changes: 3 additions & 4 deletions bigquery/unit_tests/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,10 @@ def test_w_non_bytes(self):
self.assertIs(self._call_fut(non_bytes), non_bytes)

def test_w_bytes(self):
import base64

source = b'source'
expected = base64.standard_b64encode(source)
self.assertEqual(self._call_fut(source), expected)
expected = u'c291cmNl'
converted = self._call_fut(source)
self.assertEqual(converted, expected)


class Test_timestamp_to_json(unittest.TestCase):
Expand Down

0 comments on commit 5425bc7

Please sign in to comment.