mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 03:00:04 -03:30
Merge pull request #1061 from ryanpetrello/fix-1042
fix a unicode bug in the stdout endpoint when ?content_encoding=base64
This commit is contained in:
@@ -4641,7 +4641,7 @@ class UnifiedJobStdout(RetrieveAPIView):
|
|||||||
return Response(mark_safe(data))
|
return Response(mark_safe(data))
|
||||||
if target_format == 'json':
|
if target_format == 'json':
|
||||||
if content_encoding == 'base64' and content_format == 'ansi':
|
if content_encoding == 'base64' and content_format == 'ansi':
|
||||||
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': b64encode(content)})
|
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': b64encode(content.encode('utf-8'))})
|
||||||
elif content_format == 'html':
|
elif content_format == 'html':
|
||||||
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': body})
|
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': body})
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -251,3 +253,19 @@ def test_text_with_unicode_stdout(sqlite_copy_expert, Parent, Child, relation,
|
|||||||
|
|
||||||
response = get(url, user=admin, expect=200)
|
response = get(url, user=admin, expect=200)
|
||||||
assert response.content.splitlines() == ['オ%d' % i for i in range(3)]
|
assert response.content.splitlines() == ['オ%d' % i for i in range(3)]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_unicode_with_base64_ansi(sqlite_copy_expert, get, admin):
|
||||||
|
job = Job()
|
||||||
|
job.save()
|
||||||
|
for i in range(3):
|
||||||
|
JobEvent(job=job, stdout=u'オ{}\n'.format(i), start_line=i).save()
|
||||||
|
url = reverse(
|
||||||
|
'api:job_stdout',
|
||||||
|
kwargs={'pk': job.pk}
|
||||||
|
) + '?format=json&content_encoding=base64&content_format=ansi'
|
||||||
|
|
||||||
|
response = get(url, user=admin, expect=200)
|
||||||
|
content = base64.b64decode(json.loads(response.content)['content'])
|
||||||
|
assert content.splitlines() == ['オ%d' % i for i in range(3)]
|
||||||
|
|||||||
Reference in New Issue
Block a user