Skip to content

Commit 2abdb1d

Browse files
author
Jesus Llorente Santos
committed
Improved filtering of empty fields
1 parent acb0352 commit 2abdb1d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

iptc/ip4tc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,12 +1492,16 @@ def _filter_empty_field(data_d):
14921492
Remove empty lists from dictionary values
14931493
Before: {'target': {'CHECKSUM': {'checksum-fill': []}}}
14941494
After: {'target': {'CHECKSUM': {'checksum-fill': ''}}}
1495+
Before: {'tcp': {'dport': ['22']}}}
1496+
After: {'tcp': {'dport': '22'}}}
14951497
"""
14961498
for k, v in data_d.items():
14971499
if isinstance(v, dict):
14981500
data_d[k] = _filter_empty_field(v)
14991501
elif isinstance(v, list) and len(v) != 0:
15001502
v = [_filter_empty_field(_v) if isinstance(_v, dict) else _v for _v in v ]
1503+
if isinstance(v, list) and len(v) == 1:
1504+
data_d[k] = v.pop()
15011505
elif isinstance(v, list) and len(v) == 0:
15021506
data_d[k] = ''
15031507
return data_d

0 commit comments

Comments
 (0)