Skip to content

Commit 1e1df14

Browse files
committed
fixing RecursionError where using non UTF-8 character #227
1 parent bbd7c08 commit 1e1df14

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
DeepDiff Change log
1+
# DeepDiff Change log
22

3+
- v5-2-3: Retaining the order of multiple dictionary items added via Delta. Fixed the typo with yml files in deep cli. Fixing Grep RecursionError where using non UTF-8 character.
34
- v5-2-2: Fixed Delta serialization when None type is present.
45
- v5-2-0: Removed Murmur3 as the preferred hashing method. Using SHA256 by default now. Added commandline for deepdiff. Added group_by. Added math_epsilon. Improved ignoring of NoneType.
56
- v5-0-2: Bug Fix NoneType in ignore type groups https://github.com/seperman/deepdiff/issues/207

deepdiff/search.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ def __search_iterable(self,
223223
parent="root",
224224
parents_ids=frozenset()):
225225
"""Search iterables except dictionaries, sets and strings."""
226-
227226
for i, thing in enumerate(obj):
228227
new_parent = "{}[{}]".format(parent, i)
229228
if self.__skip_this(thing, parent=new_parent):
@@ -271,7 +270,7 @@ def __search_tuple(self, obj, item, parent, parents_ids):
271270

272271
def __search(self, obj, item, parent="root", parents_ids=frozenset()):
273272
"""The main search method"""
274-
273+
# import pytest; pytest.set_trace()
275274
if self.__skip_this(item, parent):
276275
return
277276

@@ -299,7 +298,7 @@ def __search(self, obj, item, parent="root", parents_ids=frozenset()):
299298
self.warning_num += 1
300299
self.__search_iterable(obj, item, parent, parents_ids)
301300

302-
elif isinstance(obj, Iterable):
301+
elif isinstance(obj, Iterable) and not isinstance(obj, strings):
303302
self.__search_iterable(obj, item, parent, parents_ids)
304303

305304
else:

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55

66
DeepDiff Changelog
77

8+
- v5-2-3: Retaining the order of multiple dictionary items added via Delta. Fixed the typo with yml files in deep cli. Fixing Grep RecursionError where using non UTF-8 character.
89
- v5-2-2: Fixed Delta serialization when None type is present.
910
- v5-2-0: Removed Murmur3 as the preferred hashing method. Using SHA256 by default now. Added commandline for deepdiff. Added group_by. Added math_epsilon. Improved ignoring of NoneType.
1011
- v5-0-2: Bug Fix NoneType in ignore type groups https://github.com/seperman/deepdiff/issues/207

tests/test_search.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ def test_number_in_list(self):
2929
result = {"matched_values": {'root[1]'}}
3030
assert DeepSearch(obj, item, verbose_level=1) == result
3131

32+
def test_number_in_list2(self):
33+
obj = ["a", "10", 10, 20]
34+
item = 10
35+
result = {"matched_values": {'root[2]'}}
36+
assert DeepSearch(obj, item, verbose_level=1) == result
37+
38+
def test_number_in_list3(self):
39+
obj = ["a", "10", 10, 20]
40+
item = "10"
41+
result = {"matched_values": {'root[1]'}}
42+
assert DeepSearch(obj, item, verbose_level=1) == result
43+
3244
def test_string_in_root(self):
3345
obj = "long string somewhere"
3446
result = {"matched_values": {'root'}}
@@ -334,3 +346,22 @@ def test_grep_dict(self):
334346
}
335347
ds = obj | grep(item)
336348
assert ds == {'matched_values': {"root['ingredients'][3]"}}
349+
350+
def test_grep_dict_in_dict(self):
351+
obj = {
352+
"x": {
353+
"y": [
354+
"aaaaaa\u0142 bbbbb"
355+
]
356+
},
357+
"z": "z",
358+
}
359+
item = {"z": "z"}
360+
result = obj | grep(item)
361+
assert {} == result
362+
363+
def test_grep_with_non_utf8_chars(self):
364+
obj = "aaaaaa\u0142 bbbbb"
365+
item = {"z": "z"}
366+
result = obj | grep(item)
367+
assert {} == result

0 commit comments

Comments
 (0)