Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Packs/Base/ReleaseNotes/1_41_71.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Scripts

##### CommonServerPython

- Fixed an issue in the ***tableToMarkdown*** function where passing a single-key dictionary with an empty list value and no explicit headers caused an `IndexError: list index out of range`.
7 changes: 4 additions & 3 deletions Packs/Base/Scripts/CommonServerPython/CommonServerPython.py
Original file line number Diff line number Diff line change
Expand Up @@ -2404,9 +2404,10 @@ def tableToMarkdown(name, t, headers=None, headerTransform=None, removeNull=Fals
if not headers and isinstance(t, dict) and len(t.keys()) == 1:
# in case of a single key, create a column table where each element is in a different row.
headers = list(t.keys())
# if the value of the single key is a list, unpack it for creating a column table.
if isinstance(list(t.values())[0], list):
t = list(t.values())[0]
# if the value of the single key is a non-empty list, unpack it for creating a column table.
Comment thread
MosheEichler marked this conversation as resolved.
single_value = list(t.values())[0]
if isinstance(single_value, list) and single_value:
t = single_value

if not isinstance(t, list):
t = [t]
Expand Down
14 changes: 14 additions & 0 deletions Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,20 @@ def test_single_key_dict():
)
assert table_single_key_dict_nested == expected_single_key_dict_nested_tbl

@staticmethod
def test_single_key_dict_with_empty_list():
"""
Given:
- A single-key dict whose value is an empty list, and no explicit headers.
When:
- Calling tableToMarkdown.
Then:
- Should return a 'No entries.' table without raising an IndexError.
"""
table = tableToMarkdown('tableToMarkdown test with single key dict and empty list',
{'Name Servers': []})
assert '|Name Servers|\n|---|\n| |' in table

@staticmethod
def test_dict_with_special_character():
"""
Expand Down
2 changes: 1 addition & 1 deletion Packs/Base/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Base",
"description": "The base pack for Cortex XSOAR.",
"support": "xsoar",
"currentVersion": "1.41.70",
"currentVersion": "1.41.71",
"author": "Cortex XSOAR",
"serverMinVersion": "6.0.0",
"url": "https://www.paloaltonetworks.com/cortex",
Expand Down
Loading