Skip to content

Commit ae63b53

Browse files
committed
Explicitly construct a JSON backend and disable fallthrough.
Avoids issues reported in jsonpickle/jsonpickle#550. Also, provides better isolation from the global state in jsonpickle.
1 parent 54f5f1f commit ae63b53

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

jaraco/net/http/cookies.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ class Shelf(collections.abc.MutableMapping):
2525
def __init__(self, filename):
2626
self.filename = pathlib.Path(filename)
2727
self.store = dict()
28+
# ensure stricter, non-YAML backend is selected (jsonpickle/jsonpickle#550)
29+
self.backend = jsonpickle.backend.JSONBackend(fallthrough=False)
2830
with contextlib.suppress(Exception):
2931
self._load()
3032

3133
def _load(self):
32-
self.store = jsonpickle.decode(self.filename.read_text(encoding='utf-8'))
34+
self.store = jsonpickle.decode(
35+
self.filename.read_text(encoding='utf-8'), backend=self.backend
36+
)
3337

3438
def _save(self):
35-
self.filename.write_text(jsonpickle.encode(self.store), encoding='utf-8')
39+
self.filename.write_text(
40+
jsonpickle.encode(self.store, backend=self.backend), encoding='utf-8'
41+
)
3642

3743
def __getitem__(self, *args, **kwargs):
3844
return self.store.__getitem__(*args, **kwargs)

0 commit comments

Comments
 (0)