mirror of
https://github.com/docker/compose.git
synced 2025-07-22 05:04:27 +02:00
Handle non-utf8 unicode without raising an error.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
67dc90ec0e
commit
26c7dd3712
@ -457,7 +457,7 @@ def parse_environment(environment):
|
|||||||
|
|
||||||
def split_env(env):
|
def split_env(env):
|
||||||
if isinstance(env, six.binary_type):
|
if isinstance(env, six.binary_type):
|
||||||
env = env.decode('utf-8')
|
env = env.decode('utf-8', 'replace')
|
||||||
if '=' in env:
|
if '=' in env:
|
||||||
return env.split('=', 1)
|
return env.split('=', 1)
|
||||||
else:
|
else:
|
||||||
|
@ -95,7 +95,7 @@ def stream_as_text(stream):
|
|||||||
"""
|
"""
|
||||||
for data in stream:
|
for data in stream:
|
||||||
if not isinstance(data, six.text_type):
|
if not isinstance(data, six.text_type):
|
||||||
data = data.decode('utf-8')
|
data = data.decode('utf-8', 'replace')
|
||||||
yield data
|
yield data
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .. import unittest
|
from .. import unittest
|
||||||
from compose import utils
|
from compose import utils
|
||||||
|
|
||||||
@ -14,3 +17,16 @@ class JsonSplitterTestCase(unittest.TestCase):
|
|||||||
utils.json_splitter(data),
|
utils.json_splitter(data),
|
||||||
({'foo': 'bar'}, '{"next": "obj"}')
|
({'foo': 'bar'}, '{"next": "obj"}')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class StreamAsTextTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_stream_with_non_utf_unicode_character(self):
|
||||||
|
stream = [b'\xed\xf3\xf3']
|
||||||
|
output, = utils.stream_as_text(stream)
|
||||||
|
assert output == '<EFBFBD><EFBFBD><EFBFBD>'
|
||||||
|
|
||||||
|
def test_stream_with_utf_character(self):
|
||||||
|
stream = ['ěĝ'.encode('utf-8')]
|
||||||
|
output, = utils.stream_as_text(stream)
|
||||||
|
assert output == 'ěĝ'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user