From e2123762279f8df5b2a1b7605ee6554d18bb9ab9 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Thu, 30 May 2024 00:45:47 +0200 Subject: [PATCH] Fix passing unicode variables to evaljs --- dukpy/evaljs.py | 2 +- tests/test_evaljs.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dukpy/evaljs.py b/dukpy/evaljs.py index d2d2526..3e9c498 100644 --- a/dukpy/evaljs.py +++ b/dukpy/evaljs.py @@ -45,7 +45,7 @@ class JSInterpreter(object): Returns the last object on javascript stack. """ - jsvars = json.dumps(kwargs) + jsvars = json.dumps(kwargs, ensure_ascii=False) jscode = self._adapt_code(code) if not isinstance(jscode, bytes): diff --git a/tests/test_evaljs.py b/tests/test_evaljs.py index 46fc73b..36dd30f 100644 --- a/tests/test_evaljs.py +++ b/tests/test_evaljs.py @@ -29,6 +29,10 @@ class TestEvalJS(unittest.TestCase): s = dukpy.evaljs("dukpy.c + '華'", c="華") assert s == '華華' + def test_unicode_emoji(self): + s = dukpy.evaljs("dukpy.c + '華'", c="🏠") + assert s == '🏠華' + def test_eval_files(self): testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'test.js') with open(testfile) as f: