Skip to content

Commit 03b3957

Browse files
committed
Added the no-escape option for JSON.GET command, to get correct non-ascii characters
1 parent 0a35994 commit 03b3957

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

rejson/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,19 @@ def jsondel(self, name, path=Path.rootPath()):
103103
"""
104104
return self.execute_command('JSON.DEL', name, str_path(path))
105105

106-
def jsonget(self, name, *args):
106+
def jsonget(self, name, *args, no_escape=False):
107107
"""
108108
Get the object stored as a JSON value at key ``name``
109109
``args`` is zero or more paths, and defaults to root path
110+
```no_escape`` is a boolean flag to add no_escape option to get non-ascii characters
110111
"""
111112
pieces = [name]
113+
if no_escape:
114+
pieces.append('noescape')
115+
112116
if len(args) == 0:
113117
pieces.append(Path.rootPath())
118+
114119
else:
115120
for p in args:
116121
pieces.append(str_path(p))

tests/test_rejson.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from unittest import TestCase
55
from rejson import Client, Path
66

7-
87
rj = None
98
port = 6379
109

@@ -25,6 +24,15 @@ def testJSONSetGetDelShouldSucceed(self):
2524
self.assertEqual(1, rj.jsondel('foo'))
2625
self.assertFalse(rj.exists('foo'))
2726

27+
def testJSONSetGetDelNonAsciiShouldSucceed(self):
28+
"Test non-ascii JSONSet/Get/Del"
29+
30+
self.assertTrue(rj.jsonset('notascii', Path.rootPath(), 'hyvää-élève'))
31+
self.assertNotEqual('hyvää-élève', rj.jsonget('notascii'))
32+
self.assertEqual('hyvää-élève', rj.jsonget('notascii', no_escape=True))
33+
self.assertEqual(1, rj.jsondel('notascii'))
34+
self.assertFalse(rj.exists('notascii'))
35+
2836
def testJSONSetExistentialModifiersShouldSucceed(self):
2937
"Test JSONSet's NX/XX flags"
3038

0 commit comments

Comments
 (0)