Skip to content

Commit

Permalink
Fix handle values bug [Google Sheets] (#30500)
Browse files Browse the repository at this point in the history
* fix handle values bug [Google Sheets]

* update RN

* update Docker and RN

* flake8

* Bump pack from version GoogleSheets to 1.0.36.

* add docstring to "handle_values_input" function

---------

Co-authored-by: Content Bot <[email protected]>
  • Loading branch information
israelpoli and Content Bot authored Nov 6, 2023
1 parent 82f9981 commit 1c3be2c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
35 changes: 27 additions & 8 deletions Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ast
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401
import json
Expand Down Expand Up @@ -105,15 +106,33 @@ def handle_values_input(values: str) -> list:
Returns:
(list) A list of lists of the values for this example [[1,2,3],[4,5,6]...]
"""
if not values:
raise ValueError('Wrong format of values entered, please check the documentation')
split_by_brackets = re.findall("\[(.*?)\]", values)
res_for_values_req = []
for element in split_by_brackets:
res_for_values_req.append(element.split(","))

if not res_for_values_req:
raise ValueError('Wrong format of values entered, please check the documentation')
# Validate that the user has entered valid values
if not values or not re.findall("\[(.*?)\]", values):
raise ValueError(
"Wrong format of values entered, please check the documentation"
)

# Converting the values the user entered into an array of arrays
values_as_array = ast.literal_eval(values)

# Checks whether the given values are a singular empty list, such as "[]".
# if that's the case, it will convert it to [[]] (a list of lists).
if isinstance(values_as_array, list) and len(values_as_array) == 0:
values_as_array = [values_as_array]

# Checks whether the given values are a single non-empty list, e.g., "[1,2,3]".
# in such a case, it will convert it to [[1,2,3]] (a list of lists).
elif not all(isinstance(item, list) for item in values_as_array):
values_as_array = [values_as_array]

# Handling all values including the `None` value to be string
res_for_values_req = []
for element in values_as_array:
if not element:
res_for_values_req.append([""])
continue
res_for_values_req.append([str(value) for value in element])

return res_for_values_req

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ def test_create_list_id_title():

handle_values_input_parametrized = [
("[1,2,3],[4,5,6]", [['1', '2', '3'], ['4', '5', '6']]),
("[1,'test, for test',3],[4,5,6]", [['1', 'test, for test', '3'], ['4', '5', '6']]),
("[1,[2],3],[4,5,6]", [['1', '[2]', '3'], ['4', '5', '6']]),
("[1,2]", [['1', '2']]),
("[1]", [['1']]),
("[]", [['']])
("[]", [['']]),
("[[1,2,3],[4,5,6]]", [['1', '2', '3'], ['4', '5', '6']])
]


Expand Down
6 changes: 6 additions & 0 deletions Packs/GoogleSheets/ReleaseNotes/1_0_36.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Google Sheets
- Updated the Docker image to: *demisto/googleapi-python3:1.0.0.78508*.
- Fixed an issue where the ***google-sheets-value-append*** command incorrectly appended values to a spreadsheet.
2 changes: 1 addition & 1 deletion Packs/GoogleSheets/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Google Sheets",
"description": "The Google Sheets API is a RESTful interface that lets you read and modify a spreadsheet's data. The most common uses of this API include the following tasks- create spreadsheets, read and write spreadsheets cells, update spreadsheet formatting",
"support": "xsoar",
"currentVersion": "1.0.35",
"currentVersion": "1.0.36",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 1c3be2c

Please sign in to comment.