dukpy icon indicating copy to clipboard operation
dukpy copied to clipboard

some emoji not supported

Open tsuga opened this issue 2 years ago • 1 comments

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

tsuga avatar Oct 04 '22 04:10 tsuga

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

Aran-Fey avatar Feb 21 '23 08:02 Aran-Fey

Same problem here. My workaround was to use emoji.demojize(script) from the emoji library before passing the script to dukpy.

Hamza5 avatar Jun 10 '24 03:06 Hamza5

Same problem here. My workaround was to use emoji.demojize(script) from the emoji library before passing the script to dukpy.

Have you tried with dukpy 0.4.0 recently released? Is this still an issues?

amol- avatar Jun 10 '24 12:06 amol-

Closing as it seems to work correctly on 0.4.0

>>> import dukpy
>>> dukpy.evaljs("var data = '💫'; data")
'💫'
>>> 

amol- avatar Jun 16 '24 16:06 amol-