From 62b0a3d2a607a45460334c45025770f61fd93a5e Mon Sep 17 00:00:00 2001 From: Robin van der Noord Date: Mon, 20 May 2024 20:29:51 +0200 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20prevent=20crash=20with=20unicode=20e?= =?UTF-8?q?moji=20(e.g.=20=F0=9F=8F=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 @@ def evaljs(self, code, **kwargs): 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..9fb696a 100644 --- a/tests/test_evaljs.py +++ b/tests/test_evaljs.py @@ -29,6 +29,10 @@ def test_unicode_jssrc(self): s = dukpy.evaljs("dukpy.c + '華'", c="華") assert s == '華華' + def test_unicode_emoji(self): + s = dukpy.evaljs("dukpy.c + 'B'", c="🏠") + assert s == '🏠B' + def test_eval_files(self): testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'test.js') with open(testfile) as f: From 333f5e175767419e537237643c70c51721c41753 Mon Sep 17 00:00:00 2001 From: Robin van der Noord Date: Mon, 20 May 2024 20:39:46 +0200 Subject: [PATCH 2/2] =?UTF-8?q?test:=20included=20a=20test=20with=20combin?= =?UTF-8?q?ed=20emoji=20(=F0=9F=91=8D=F0=9F=8F=BE=20=3D=20=F0=9F=91=8D+?= =?UTF-8?q?=F0=9F=8F=BE)=20to=20ensure=20that=20doesn't=20break=20either?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_evaljs.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_evaljs.py b/tests/test_evaljs.py index 9fb696a..babfd65 100644 --- a/tests/test_evaljs.py +++ b/tests/test_evaljs.py @@ -30,8 +30,11 @@ def test_unicode_jssrc(self): assert s == '華華' def test_unicode_emoji(self): - s = dukpy.evaljs("dukpy.c + 'B'", c="🏠") - assert s == '🏠B' + s1 = dukpy.evaljs("dukpy.c + 'B'", c="🏠") + assert s1 == '🏠B' + + s2 = dukpy.evaljs("dukpy.c + 'C'", c="👍🏾") + assert s2 == '👍🏾C' def test_eval_files(self): testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'test.js')