Skip to content

Commit

Permalink
Merge pull request #7918 from ryanpetrello/surro-get-outta-here
Browse files Browse the repository at this point in the history
make event stdout encoding more resilient to UTF-16 surrogate pairs

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
  • Loading branch information
softwarefactory-project-zuul[bot] authored Aug 18, 2020
2 parents e7281a7 + 33e2c05 commit d452c1d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This is a list of high-level changes for each release of AWX. A full list of com
- Upgraded git-python to fix a bug that caused workflows to sometimes fail - https://github.com/ansible/awx/issues/6119
- Fixed a bug in the AWX CLI that prevented Workflow nodes from importing properly - https://github.com/ansible/awx/issues/7793
- Fixed a bug in the awx.awx collection release process that templated the wrong version - https://github.com/ansible/awx/issues/7870
- Fixed a bug that caused errors rendering stdout that contained UTF-16 surrogate pairs - https://github.com/ansible/awx/pull/7918

## 14.0.0 (Aug 6, 2020)
- As part of our commitment to inclusivity in open source, we recently took some time to audit AWX's source code and user interface and replace certain terminology with more inclusive language. Strictly speaking, this isn't a bug or a feature, but we think it's important and worth calling attention to:
Expand Down
18 changes: 18 additions & 0 deletions awx/api/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
# Django REST Framework
from rest_framework import renderers
from rest_framework.request import override_method
from rest_framework.utils import encoders


class SurrogateEncoder(encoders.JSONEncoder):

def encode(self, obj):
ret = super(SurrogateEncoder, self).encode(obj)
try:
ret.encode()
except UnicodeEncodeError as e:
if 'surrogates not allowed' in e.reason:
ret = ret.encode('utf-8', 'replace').decode()
return ret


class DefaultJSONRenderer(renderers.JSONRenderer):

encoder_class = SurrogateEncoder


class BrowsableAPIRenderer(renderers.BrowsableAPIRenderer):
Expand Down
2 changes: 1 addition & 1 deletion awx/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def IS_TESTING(argv=None):
'awx.api.parsers.JSONParser',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'awx.api.renderers.DefaultJSONRenderer',
'awx.api.renderers.BrowsableAPIRenderer',
),
'DEFAULT_METADATA_CLASS': 'awx.api.metadata.Metadata',
Expand Down

0 comments on commit d452c1d

Please sign in to comment.