Skip to content

Commit fe5feef

Browse files
content-botspearmin10iyeshaya
authored
Fixed an issue where is existing key and isn't existing key dont'… (#15339) (#15437)
* Fixed an issue where `is existing key` and `isn't existing key` dont' work. * Modified pack_metadata.json * Delete README.md.orig Co-authored-by: iyeshaya <[email protected]> Co-authored-by: Masahiko Inoue <[email protected]> Co-authored-by: iyeshaya <[email protected]>
1 parent aa334cd commit fe5feef

File tree

7 files changed

+445
-266
lines changed

7 files changed

+445
-266
lines changed

Packs/ExtFilter/ReleaseNotes/1_1_7.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Scripts
3+
##### ExtFilter
4+
- Fixed an issue where `is existing key` and `isn't existing key` dont' work.
5+
- Revised the mistakes on the document
6+

Packs/ExtFilter/Scripts/ExtFilter/ExtFilter.py

+28-21
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import demistomock as demisto # noqa: F401
1111
from CommonServerPython import * # noqa: F401
1212

13-
PATALG_BINARY = 0
13+
PATALG_BINARY: int = 0
1414
PATALG_WILDCARD: int = 1
15-
PATALG_REGEX = 2
15+
PATALG_REGEX: int = 2
1616

17-
ITERATE_NODE = 0
18-
ITERATE_VALUE = 1
19-
ITERATE_KEY = 2
17+
ITERATE_NODE: int = 0
18+
ITERATE_VALUE: int = 1
19+
ITERATE_KEY: int = 2
2020

2121

2222
class Value:
@@ -76,14 +76,15 @@ def set(node: Dict[str, Any], path: str, value: Any):
7676
@staticmethod
7777
def get_value(node: Dict[str, Any], path: str) -> Optional[Value]:
7878
val = None
79+
key = None
7980
comps = path.split('.')
8081
while comps:
8182
res = Ddict.__search(node if val is None else val, comps)
8283
if res is None:
8384
return None
84-
_, val, comps = res
85+
key, val, comps = res
8586

86-
return None if val is None else Value(val)
87+
return None if key is None else Value(val)
8788

8889
@staticmethod
8990
def get(node: Dict[str, Any], path: str) -> Any:
@@ -873,11 +874,17 @@ def filter_with_expressions(self,
873874

874875
for x in self.__conds_items(conds, root):
875876
coptype, cconds = x
876-
child = self.filter_value(
877-
child, coptype, cconds, None, inlist and parent is None)
878-
if not child:
879-
return None
880-
child = child.value
877+
878+
if coptype in ("is", "isn't") and \
879+
isinstance(cconds, str) and cconds == "existing key":
880+
if (coptype == "is") != bool(path and Ddict.get_value(root, path)):
881+
return None
882+
else:
883+
child = self.filter_value(
884+
child, coptype, cconds, None, inlist and parent is None)
885+
if not child:
886+
return None
887+
child = child.value
881888

882889
if parent:
883890
if isinstance(parent, dict):
@@ -1118,15 +1125,11 @@ def filter_value(
11181125
if not inlist and isinstance(root, list):
11191126
return self.filter_values(root, optype, conds, path)
11201127

1121-
filstr = conds
1122-
if isinstance(filstr, str) and filstr == "existing key":
1123-
if optype == "is":
1124-
if path and Ddict.get_value(root, path):
1125-
return Value(root)
1126-
else: # isn't
1127-
if not path or not Ddict.get_value(root, path):
1128-
return Value(root)
1128+
if isinstance(conds, str) and conds == "existing key":
1129+
if (optype == "is") == bool(path and Ddict.get_value(root, path)):
1130+
return Value(root)
11291131
return None
1132+
11301133
if path:
11311134
if not inlist and isinstance(root, list):
11321135
return self.filter_values(root, optype, conds, path)
@@ -1718,7 +1721,11 @@ def parse_conds_json(
17181721
"""
17191722
if only_parse_for_string and not isinstance(jstr, str):
17201723
return jstr
1721-
return json.loads(jstr)
1724+
1725+
try:
1726+
return json.loads(jstr)
1727+
except json.JSONDecodeError:
1728+
return jstr
17221729

17231730
def parse_and_extract_conds_json(
17241731
self,

Packs/ExtFilter/Scripts/ExtFilter/ExtFilter.yml

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
commonfields:
22
id: ExtFilter
33
version: -1
4-
contentitemexportablefields:
5-
contentitemfields:
6-
fromServerVersion: ""
74
name: ExtFilter
85
script: ''
96
type: python

Packs/ExtFilter/Scripts/ExtFilter/Pipfile

+13-10
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,29 @@ pytest-datadir-ng = "*"
1414
freezegun = "*"
1515
pytest-json = "*"
1616
vcrpy = "*"
17+
pytest-cov = "*"
18+
hypothesis = "*"
1719
flake8 = "*"
1820

1921
[packages]
20-
certifi = "==2020.12.5"
21-
chardet = "==4.0.0"
22+
certifi = "==2021.5.30"
23+
charset-normalizer = "==2.0.1"
2224
dateparser = "==1.0.0"
23-
funcy = "==1.15"
24-
idna = "==2.10"
25+
filelock = "==3.0.12"
26+
funcy = "==1.16"
27+
idna = "==3.2"
2528
olefile = "==0.46"
26-
python-dateutil = "==2.8.1"
29+
python-dateutil = "==2.8.2"
2730
pytz = "==2021.1"
28-
regex = "==2021.4.4"
29-
requests = "==2.25.1"
31+
regex = "==2021.7.6"
32+
requests = "==2.26.0"
3033
requests-file = "==1.5.1"
3134
six = "==1.16.0"
32-
tldextract = "==2.2.3"
35+
tldextract = "==3.1.0"
3336
tzlocal = "==2.1"
34-
urllib3 = "==1.26.4"
37+
urllib3 = "==1.26.6"
3538
PySocks = "==1.7.1"
3639
PyYAML = "==5.4.1"
3740

3841
[requires]
39-
python_version = "3.7"
42+
python_version = "3.9"

0 commit comments

Comments
 (0)