mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 02:19:58 -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:
commit
e2d4ef31fd
@ -4641,7 +4641,7 @@ class UnifiedJobStdout(RetrieveAPIView):
|
||||
return Response(mark_safe(data))
|
||||
if target_format == 'json':
|
||||
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':
|
||||
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': body})
|
||||
return Response(data)
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import base64
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
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)
|
||||
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)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user