Skip to content

Commit

Permalink
Fix carriage return issue in get list row (#31020)
Browse files Browse the repository at this point in the history
* add fix and unit test

* added rn

* revert fix

* fixes added back

* fixes

* update docker

* Bump pack from version CommonScripts to 1.12.46.

---------

Co-authored-by: Content Bot <bot@demisto.com>
Co-authored-by: JudithB <132264628+jbabazadeh@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 22, 2023
1 parent aead772 commit c9f362d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Packs/CommonScripts/ReleaseNotes/1_12_46.md
@@ -0,0 +1,6 @@

#### Scripts

##### GetListRow
- Fixed an issue where sometimes a redundant `\r` would appear at the end of the line.
- Updated the Docker image to: *demisto/python3:3.10.13.80593*.
3 changes: 2 additions & 1 deletion Packs/CommonScripts/Scripts/GetlistRow/GetListRow.py
Expand Up @@ -18,7 +18,8 @@ def validate_header_exists(headers, header):


def list_to_headers_and_lines(list_data, list_separator: str):
lines_and_headers = [line.split(list_separator) for line in list_data.split('\n')]
lines_and_headers = [(line.replace("\r", "") if line.endswith("\r") else line).split(list_separator)
for line in list_data.split('\n')]
headers = lines_and_headers[0]
return headers, lines_and_headers[1:]

Expand Down
2 changes: 1 addition & 1 deletion Packs/CommonScripts/Scripts/GetlistRow/GetListRow.yml
Expand Up @@ -42,7 +42,7 @@ script: '-'
subtype: python3
timeout: '0'
type: python
dockerimage: demisto/python3:3.10.12.65389
dockerimage: demisto/python3:3.10.13.80593
runas: DBotWeakRole
tests:
- No tests (auto formatted)
Expand Down
35 changes: 35 additions & 0 deletions Packs/CommonScripts/Scripts/GetlistRow/GetListRow_test.py
Expand Up @@ -173,3 +173,38 @@ def test_context_path_are_correct(mocker, data, parse_all, header, value, expect
res = parse_list(parse_all, header, value, list_name="getListRow", list_separator='\n')
assert res.outputs_prefix == 'GetListRow'
assert res.outputs_key_field == expected_context_key


@pytest.mark.parametrize(
"list_data, expected_headers, expected_lines",
[
("header_a ,header_b\nline_1_item_a,line_1_item_b\nline_2_item_a,line_2_item_b",
['header_a ', 'header_b'],
[['line_1_item_a', 'line_1_item_b'], ['line_2_item_a', 'line_2_item_b']]),
("header_a ,header_b\nline\r_1_item_a,line_1_item_b\nline\r_2_item_a,line_2_item_b",
['header_a ', 'header_b'],
[['line\r_1_item_a', 'line_1_item_b'], ['line\r_2_item_a', 'line_2_item_b']]),
("header_a ,header_b\r\nline_1_item_a,line_1_item_b\r\nline_2_item_a,line_2_item_b",
['header_a ', 'header_b'],
[['line_1_item_a', 'line_1_item_b'], ['line_2_item_a', 'line_2_item_b']])
]
)
def test_list_to_headers_and_lines(list_data, expected_headers, expected_lines):
"""
Given:
- list_data.
- Case 1: list data without any \r.
- Case 2: list data with \r in the middle of a line.
- Case 3: list data with \r followed by \n at the end of each line (except for last).
When:
- Running list_to_headers_and_lines.
Then:
- Ensure that the right parts of line was parsed into headers & lines.
- Case 1: Should split the lines by \n.
- Case 2: Should split the lines by \n and not do anything about the \r.
- Case 3: Should split the lines by \r\n.
"""
from GetListRow import list_to_headers_and_lines
headers, lines = list_to_headers_and_lines(list_data, ",")
assert expected_headers == headers
assert expected_lines == lines
2 changes: 1 addition & 1 deletion Packs/CommonScripts/pack_metadata.json
Expand Up @@ -2,7 +2,7 @@
"name": "Common Scripts",
"description": "Frequently used scripts pack.",
"support": "xsoar",
"currentVersion": "1.12.45",
"currentVersion": "1.12.46",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit c9f362d

Please sign in to comment.