Skip to content

Commit

Permalink
fix: skip restricted key check when key is not a string
Browse files Browse the repository at this point in the history
Fixes #179
  • Loading branch information
dgilland committed Feb 20, 2023
1 parent 869523a commit 030403a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/pydash/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def _base_get_object(obj, key, default=UNSET):


def _raise_if_restricted_key(key):
if not isinstance(key, str):
return
# Prevent access to dunder-methods since this could expose access to globals through leaky
# attributes such as obj.__init__.__globals__.
if len(key) > 4 and key.isascii() and key.startswith("__") and key.endswith("__"):
Expand Down
1 change: 1 addition & 0 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def test_for_in_right(case, expected):
(({object: 1}, object), 1),
(({object: {object: 1}}, [object, object]), 1),
(({1: {"name": "John Doe"}}, "1.name"), "John Doe"),
((helpers.Object(), "[0].field"), None),
],
)
def test_get(case, expected):
Expand Down

0 comments on commit 030403a

Please sign in to comment.