Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dpath/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def match(segments: Path, glob: Glob):
# Let's see if the glob matches. We will turn any kind of
# exception while attempting to match into a False for the
# match.
if not fnmatchcase(s, g):
if not fnmatchcase(s, int_str(g)):
return False
except:
return False
Expand Down
13 changes: 13 additions & 0 deletions tests/test_get_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ def test_get_glob_single():
assert dpath.get(ehash, ['doesnt', '*', 'exist'], default=6) == 6


def test_integer_glob_with_string_mapping_key():
obj = {'records': {'0': 'original', '1': 'unrelated'}}
path = ['records', 0]

assert dpath.get(obj, path) == 'original'
assert dpath.values(obj, path) == ['original']
assert dpath.search(obj, path) == {'records': {'0': 'original'}}
assert dpath.set(obj, path, 'updated') == 1
assert obj == {'records': {'0': 'updated', '1': 'unrelated'}}
assert dpath.delete(obj, path) == 1
assert obj == {'records': {'1': 'unrelated'}}


def test_get_glob_multiple():
ehash = {
"a": {
Expand Down
6 changes: 6 additions & 0 deletions tests/test_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ def test_match(self, pair):
(segments, glob) = pair
assert api.match(segments, glob) is True

@given(st.integers())
def test_match_integer_glob_with_string_segment(self, number):
assert api.match([str(number)], [number]) is True
assert api.match([number], [str(number)]) is True
assert api.match([str(number) + '0'], [number]) is False

@given(random_segments_with_nonmatching_glob())
def test_match_nonmatching(self, pair):
'''
Expand Down