dukpy
dukpy copied to clipboard
some emoji not supported
I'm getting an error when the js code contains a special emoji.
MWE:
dukpy.evaljs("var data = '💫'; data")
Error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 1: invalid continuation byte
Thank you
I'm also having issues with emojis, though with a different error:
>>> dukpy.evaljs('"\u26a1\ufe0e \ud83d\udca6"')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Aran-Fey\AppData\Roaming\Python\Python311\site-packages\dukpy\evaljs.py", line 138, in evaljs
return JSInterpreter().evaljs(code, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Aran-Fey\AppData\Roaming\Python\Python311\site-packages\dukpy\evaljs.py", line 52, in evaljs
jscode = jscode.encode('utf-8')
^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 4-5: surrogates not allowed
And even if I "fix" the string as suggested here, dukpy still crashes on the way back:
>>> code = '"\u26a1\ufe0e \ud83d\udca6"'.encode('utf-16', 'surrogatepass').decode('utf-16')
>>> code
'"⚡︎ 💦"'
>>> dukpy.evaljs(code)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Aran-Fey\AppData\Roaming\Python\Python311\site-packages\dukpy\evaljs.py", line 138, in evaljs
return JSInterpreter().evaljs(code, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Aran-Fey\AppData\Roaming\Python\Python311\site-packages\dukpy\evaljs.py", line 61, in evaljs
return json.loads(res.decode('utf-8'))
^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 8: invalid continuation byte
Same problem here.
My workaround was to use emoji.demojize(script)
from the emoji
library before passing the script to dukpy
.
Same problem here. My workaround was to use
emoji.demojize(script)
from theemoji
library before passing the script todukpy
.
Have you tried with dukpy 0.4.0 recently released? Is this still an issues?
Closing as it seems to work correctly on 0.4.0
>>> import dukpy
>>> dukpy.evaljs("var data = '💫'; data")
'💫'
>>>