From 58147d4f60b9cc1e973671b3a05d2d38386c0e27 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Thu, 18 Jul 2024 18:43:32 +0200 Subject: [PATCH] Fix #1030: truncate resulting Jira instead of markdown source --- jbi/jira/utils.py | 7 ++++--- tests/unit/jira/test_utils.py | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/jbi/jira/utils.py b/jbi/jira/utils.py index a9b6a4b8..5e0203a4 100644 --- a/jbi/jira/utils.py +++ b/jbi/jira/utils.py @@ -9,7 +9,8 @@ def markdown_to_jira(markdown: str, max_length: int = 0) -> str: """ Convert markdown content into Jira specific markup language. """ - if max_length > 0 and len(markdown) > max_length: + jira_output = pypandoc.convert_text(markdown, "jira", format="gfm").strip() + if max_length > 0 and len(jira_output) > max_length: # Truncate on last word. - markdown = markdown[:max_length].rsplit(maxsplit=1)[0] - return pypandoc.convert_text(markdown, "jira", format="gfm").strip() # type: ignore + jira_output = jira_output[:max_length].rsplit(maxsplit=1)[0] + return jira_output # type: ignore diff --git a/tests/unit/jira/test_utils.py b/tests/unit/jira/test_utils.py index 89784ea5..0842bff2 100644 --- a/tests/unit/jira/test_utils.py +++ b/tests/unit/jira/test_utils.py @@ -71,6 +71,7 @@ def test_markdown_to_jira_with_malformed_input(): ("aa\taaa", "aa", 5), ("aaaaaa", "aaaaa", 5), ("aaaaa ", "aaaaa", 5), + ("`fo` `fo`", "{{fo}}", 9), ], ) def test_markdown_to_jira_with_max_chars(markdown, expected, max_length):