diff --git a/src/mpyl/reporting/targets/slack.py b/src/mpyl/reporting/targets/slack.py index d9e31406c..849ba0058 100644 --- a/src/mpyl/reporting/targets/slack.py +++ b/src/mpyl/reporting/targets/slack.py @@ -45,7 +45,7 @@ def to_slack_markdown(markdown: str) -> str: regex_replace = ( - (re.compile(r'\[(.*)\]\((.*)\)', flags=re.M), r'<\2|\1>'), + (re.compile(r'\[(.*?)\]\((.*?)\)'), r'<\2|\1>'), (re.compile(r'^- ', flags=re.M), '• '), (re.compile(r'^ - ', flags=re.M), ' ◦ '), (re.compile(r'^ - ', flags=re.M), ' ⬩ '), @@ -54,8 +54,8 @@ def to_slack_markdown(markdown: str) -> str: (re.compile(r'\*\*'), '*'), (re.compile(r'~~'), '~'), ) - for regex, replacement in regex_replace: - markdown = regex.sub(replacement, markdown) + for pattern, replacement in regex_replace: + markdown = re.sub(pattern, replacement, markdown) return markdown diff --git a/tests/reporting/targets/test_slack.py b/tests/reporting/targets/test_slack.py index c80413f99..6f52db45c 100644 --- a/tests/reporting/targets/test_slack.py +++ b/tests/reporting/targets/test_slack.py @@ -29,3 +29,10 @@ def test_convert_md_to_slack(self): with open(self.test_formatting_resource_path / "markdown_run_with_plan.md", encoding='utf-8') as markdown: markdown_report = to_slack_markdown(markdown.read()) assert_roundtrip(self.test_targets_resource_path / "markdown_run_slack.md", markdown_report) + + def test_should_lazy_match_links(self): + md_with_links = "*[nodeservice](https://nodeservice-96.test.nl/swagger/index.html)* " \ + "*[sbtservice](https://sbtservice-96.test.nl/swagger/index.html)*" + + assert to_slack_markdown(md_with_links) == '**' \ + ' **'