Skip to content

Commit 348f12d

Browse files
denis-guerra-labsmichaelmior
authored andcommitted
Fix bool filter type to handle None values
1 parent 288cec9 commit 348f12d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

jsonpath_ng/ext/filter.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,11 @@ def find(self, datum):
104104
found = []
105105
for data in datum:
106106
value = data.value
107-
if isinstance(self.value, int):
107+
if type(self.value) is int:
108108
try:
109109
value = int(value)
110110
except ValueError:
111111
continue
112-
elif isinstance(self.value, bool):
113-
try:
114-
value = bool(value)
115-
except ValueError:
116-
continue
117112

118113
if OPERATOR_MAP[self.op](value, self.value):
119114
found.append(data)

tests/test_jsonpath_rw_ext.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,19 @@
484484
["green"],
485485
id="boolean-filter-string-true-string-literal",
486486
),
487+
pytest.param(
488+
"foo[?flag = true].color",
489+
{
490+
"foo": [
491+
{"color": "blue", "flag": True},
492+
{"color": "green", "flag": 2},
493+
{"color": "red", "flag": "hi"},
494+
{"color": "gray", "flag": None},
495+
]
496+
},
497+
["blue"],
498+
id="boolean-filter-with-null",
499+
),
487500
)
488501

489502

0 commit comments

Comments
 (0)