Skip to content

Commit

Permalink
Improve create clickable URL (#31584)
Browse files Browse the repository at this point in the history
* Add the ability to create a clickable url with different text than the link

* RN

* revert

* added a modeling rule (#22875)

* added a modeling rule

* added a parsing rule

* added a parsing rule

* added a parsing rule

* added a parsing rule

* added a parsing rule

* added a parsing rule

* added a parsing rule

* added a parsing rule

* added a parsing rule

* added a parsing rule

* Update README.md (#23810)

Edit the file to remove duplication of command names in the right pane.

* Modeling rules fixes (#24259)

* save

* save no exit_code

* save not fail on test-modeling-rules

* remove ciscoasa changes

* Update Docker Image To demisto/chromium  (#24291)

* Updated Metadata Of Pack ExpanseV2

* Added release notes to pack ExpanseV2

* Packs/ExpanseV2/Scripts/ExpanseGenerateIssueMapWidgetScript/ExpanseGenerateIssueMapWidgetScript.yml Docker image update

* Deprecated GitHub TestData (#31573)

* CR fixes

* UT fixes

* revert f-string

* conflicts

* pack version

* conflicts

* doc

* conflicts

* Bump pack from version Base to 1.34.0.

* conflicts

* RN

* remove parameterize

* Bump pack from version Base to 1.33.26.

* pre-commit fixes

---------

Co-authored-by: guytamir10 <106061479+guytamir10@users.noreply.github.com>
Co-authored-by: ShirleyDenkberg <62508050+ShirleyDenkberg@users.noreply.github.com>
Co-authored-by: Darya Koval <72339940+daryakoval@users.noreply.github.com>
Co-authored-by: content-bot <55035720+content-bot@users.noreply.github.com>
Co-authored-by: eepstain <116078117+eepstain@users.noreply.github.com>
Co-authored-by: Content Bot <bot@demisto.com>
  • Loading branch information
7 people committed Feb 7, 2024
1 parent 8277363 commit b51210e
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
1 change: 1 addition & 0 deletions Packs/Base/.pack-ignore
Expand Up @@ -81,6 +81,7 @@ JavaScript
CPE
CPEs
debug-entry
clickable

[tests_require_network]
CommonServerPython
Expand Down
6 changes: 6 additions & 0 deletions Packs/Base/ReleaseNotes/1_33_26.md
@@ -0,0 +1,6 @@

#### Scripts

##### CommonServerPython

Added the ability to create a clickable URL with different text than the link.
14 changes: 10 additions & 4 deletions Packs/Base/Scripts/CommonServerPython/CommonServerPython.py
Expand Up @@ -2018,22 +2018,28 @@ def url_to_clickable_markdown(data, url_keys):
return data


def create_clickable_url(url):
def create_clickable_url(url, text=None):
"""
Make the given url clickable when in markdown format by concatenating itself, with the proper brackets
:type url: ``Union[List[str], str]``
:param url: the url of interest or a list of urls
:return: markdown format for clickable url
:rtype: ``str``
:type text: ``Union[List[str], str, None]``
:param text: the text of the url or a list of texts of urls.
:return: Markdown format for clickable url
:rtype: ``Union[List[str], str]``
"""
if not url:
return None
elif isinstance(url, list):
if isinstance(text, list):
assert len(url) == len(text), 'The URL list and the text list must be the same length.'
return ['[{}]({})'.format(text, item) for text, item in zip(text, url)]
return ['[{}]({})'.format(item, item) for item in url]
return '[{}]({})'.format(url, url)
return '[{}]({})'.format(text or url, url)


class JsonTransformer:
Expand Down
75 changes: 75 additions & 0 deletions Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py
Expand Up @@ -9243,3 +9243,78 @@ def test_detect_file_indicator_type(indicator, expected_result):
"""
from CommonServerPython import detect_file_indicator_type
assert detect_file_indicator_type(indicator) == expected_result


def test_create_clickable_url():
"""
Given:
One URL and one text.
When:
Running create_clickable_url function.
Then:
Assert the function returns the expected result.
A URL with different text than the link.
"""
from CommonServerPython import create_clickable_url
assert create_clickable_url('https://example.com', 'click here') == '[click here](https://example.com)'


def test_create_clickable_url_one_url_without_text():
"""
Given:
One URL.
When:
Running create_clickable_url function.
Then:
Assert the function returns the expected result.
A clickable URL with the same text as the link.
"""
from CommonServerPython import create_clickable_url
assert create_clickable_url('https://example.com', None) == '[https://example.com](https://example.com)'


def test_create_clickable_url_list_of_urls_with_list_of_text():
"""
Given:
A list of URLs and a list of texts.
When:
Running create_clickable_url function.
Then:
Assert the function returns the expected result.
A list of URLs with different texts than the links.
"""
from CommonServerPython import create_clickable_url
expected = ['[click here1](https://example1.com)', '[click here2](https://example2.com)']
assert create_clickable_url(['https://example1.com', 'https://example2.com'], ['click here1', 'click here2']) == expected


def test_create_clickable_url_list_of_urls_without_text():
"""
Given:
A list of URLs without text.
When:
Running create_clickable_url function.
Then:
Assert the function returns the expected result.
A list URLs without texts as the links.
"""
from CommonServerPython import create_clickable_url
expected = ['[https://example1.com](https://example1.com)', '[https://example2.com](https://example2.com)']
assert create_clickable_url(['https://example1.com', 'https://example2.com'], None) == expected


def test_create_clickable_test_wrong_text_value():
"""
Given:
A list of links and texts (not in teh same length).
When:
Running create_clickable_url function.
Then:
Assert the function returns the expected error.
"""
from CommonServerPython import create_clickable_url
with pytest.raises(AssertionError) as e:
assert create_clickable_url(['https://example1.com', 'https://example2.com'], ['click here1'])

assert e.type == AssertionError
assert 'The URL list and the text list must be the same length.' in e.value.args
4 changes: 2 additions & 2 deletions Packs/Base/pack_metadata.json
Expand Up @@ -2,7 +2,7 @@
"name": "Base",
"description": "The base pack for Cortex XSOAR.",
"support": "xsoar",
"currentVersion": "1.33.25",
"currentVersion": "1.33.26",
"author": "Cortex XSOAR",
"serverMinVersion": "6.0.0",
"url": "https://www.paloaltonetworks.com/cortex",
Expand All @@ -25,4 +25,4 @@
"marketplacev2",
"xpanse"
]
}
}

0 comments on commit b51210e

Please sign in to comment.