Skip to content

Commit

Permalink
Fixed an issue where is existing key and isn't existing key dont'… (
Browse files Browse the repository at this point in the history
#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 <81752898+iyeshaya@users.noreply.github.com>

Co-authored-by: Masahiko Inoue <54964121+spearmin10@users.noreply.github.com>
Co-authored-by: iyeshaya <81752898+iyeshaya@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 24, 2021
1 parent aa334cd commit fe5feef
Show file tree
Hide file tree
Showing 7 changed files with 445 additions and 266 deletions.
6 changes: 6 additions & 0 deletions Packs/ExtFilter/ReleaseNotes/1_1_7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Scripts
##### ExtFilter
- Fixed an issue where `is existing key` and `isn't existing key` dont' work.
- Revised the mistakes on the document

49 changes: 28 additions & 21 deletions Packs/ExtFilter/Scripts/ExtFilter/ExtFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401

PATALG_BINARY = 0
PATALG_BINARY: int = 0
PATALG_WILDCARD: int = 1
PATALG_REGEX = 2
PATALG_REGEX: int = 2

ITERATE_NODE = 0
ITERATE_VALUE = 1
ITERATE_KEY = 2
ITERATE_NODE: int = 0
ITERATE_VALUE: int = 1
ITERATE_KEY: int = 2


class Value:
Expand Down Expand Up @@ -76,14 +76,15 @@ def set(node: Dict[str, Any], path: str, value: Any):
@staticmethod
def get_value(node: Dict[str, Any], path: str) -> Optional[Value]:
val = None
key = None
comps = path.split('.')
while comps:
res = Ddict.__search(node if val is None else val, comps)
if res is None:
return None
_, val, comps = res
key, val, comps = res

return None if val is None else Value(val)
return None if key is None else Value(val)

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

for x in self.__conds_items(conds, root):
coptype, cconds = x
child = self.filter_value(
child, coptype, cconds, None, inlist and parent is None)
if not child:
return None
child = child.value

if coptype in ("is", "isn't") and \
isinstance(cconds, str) and cconds == "existing key":
if (coptype == "is") != bool(path and Ddict.get_value(root, path)):
return None
else:
child = self.filter_value(
child, coptype, cconds, None, inlist and parent is None)
if not child:
return None
child = child.value

if parent:
if isinstance(parent, dict):
Expand Down Expand Up @@ -1118,15 +1125,11 @@ def filter_value(
if not inlist and isinstance(root, list):
return self.filter_values(root, optype, conds, path)

filstr = conds
if isinstance(filstr, str) and filstr == "existing key":
if optype == "is":
if path and Ddict.get_value(root, path):
return Value(root)
else: # isn't
if not path or not Ddict.get_value(root, path):
return Value(root)
if isinstance(conds, str) and conds == "existing key":
if (optype == "is") == bool(path and Ddict.get_value(root, path)):
return Value(root)
return None

if path:
if not inlist and isinstance(root, list):
return self.filter_values(root, optype, conds, path)
Expand Down Expand Up @@ -1718,7 +1721,11 @@ def parse_conds_json(
"""
if only_parse_for_string and not isinstance(jstr, str):
return jstr
return json.loads(jstr)

try:
return json.loads(jstr)
except json.JSONDecodeError:
return jstr

def parse_and_extract_conds_json(
self,
Expand Down
3 changes: 0 additions & 3 deletions Packs/ExtFilter/Scripts/ExtFilter/ExtFilter.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
commonfields:
id: ExtFilter
version: -1
contentitemexportablefields:
contentitemfields:
fromServerVersion: ""
name: ExtFilter
script: ''
type: python
Expand Down
23 changes: 13 additions & 10 deletions Packs/ExtFilter/Scripts/ExtFilter/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@ pytest-datadir-ng = "*"
freezegun = "*"
pytest-json = "*"
vcrpy = "*"
pytest-cov = "*"
hypothesis = "*"
flake8 = "*"

[packages]
certifi = "==2020.12.5"
chardet = "==4.0.0"
certifi = "==2021.5.30"
charset-normalizer = "==2.0.1"
dateparser = "==1.0.0"
funcy = "==1.15"
idna = "==2.10"
filelock = "==3.0.12"
funcy = "==1.16"
idna = "==3.2"
olefile = "==0.46"
python-dateutil = "==2.8.1"
python-dateutil = "==2.8.2"
pytz = "==2021.1"
regex = "==2021.4.4"
requests = "==2.25.1"
regex = "==2021.7.6"
requests = "==2.26.0"
requests-file = "==1.5.1"
six = "==1.16.0"
tldextract = "==2.2.3"
tldextract = "==3.1.0"
tzlocal = "==2.1"
urllib3 = "==1.26.4"
urllib3 = "==1.26.6"
PySocks = "==1.7.1"
PyYAML = "==5.4.1"

[requires]
python_version = "3.7"
python_version = "3.9"
Loading

0 comments on commit fe5feef

Please sign in to comment.