-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make event stdout encoding more resilient to UTF-16 surrogate pairs #7918
make event stdout encoding more resilient to UTF-16 surrogate pairs #7918
Conversation
Build failed.
|
recheck |
There's also apparently libraries for actually handling these more gracefully: https://pypi.org/project/surrogates/ ...but I also don't know that I want to add a dependency to deal with something so esoteric. |
Build failed.
|
c04c5c3
to
8b2641c
Compare
class SurrogateEncoder(encoders.JSONEncoder): | ||
|
||
def encode(self, obj): | ||
ret = super(SurrogateEncoder, self).encode(obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little gross, but I couldn't find a less gross way to do this.
tl;dr there’s code further down the stack in DRF that ends up calling .encode()
(and it blows up), so I’m calling it, seeing if it blows up, and then fixing the problem (so it won’t blow up later)
try: | ||
ret.encode() | ||
except UnicodeEncodeError as e: | ||
if 'surrogates not allowed' in e.reason: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since ret
is just a python str this assumption lgtm 👍
Build failed.
|
recheck |
Build failed.
|
Build failed.
|
recheck |
8b2641c
to
f2c9437
Compare
Build succeeded.
|
f2c9437
to
33e2c05
Compare
Build succeeded.
|
Build succeeded (gate pipeline).
|
Given that we're returning literally any bytestream that Ansible can muster, it probably makes sense to relax
errors='strict'
a bit to avoid 500 errors.see: https://unicodebook.readthedocs.io/unicode_encodings.html#utf-16-surrogate-pairs
Run this adhoc command w/
-m shell
:printf '\uD83D\uDE00'
after (better than a 500 error):