Skip to content

Commit

Permalink
update-release-notes --text special chars (#4751)
Browse files Browse the repository at this point in the history
* update-release-notes --text special chars

* update changelog

* fix pre commit

* fix pre commit

* fix + unittests
  • Loading branch information
inbalapt1 authored Jan 5, 2025
1 parent 4b0baf8 commit 394cbb3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .changelog/4751.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Resolved an issue with handling special characters in the update-release-notes --text parameter.
type: fix
pr_number: 4751
24 changes: 24 additions & 0 deletions demisto_sdk/commands/update_release_notes/tests/update_rn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,30 @@ def test_build_rn_desc_new_file(
)
assert expected_result in desc

def test_build_rn_desc_unicode_escape_handling(self):
"""
Given
- An input string containing escaped unicode sequences such as '\\n' and '\\t'.
When
- Running the command build_rn_desc to generate the release notes description.
Then
- Validate that the escaped sequences are correctly interpreted and included
in the release notes description as their respective characters.
"""
input_text = "Line with \\n newline and \\t tab characters"
expected_output = "##### \n\n- Line with \n newline and \t tab characters\n"

update_rn = UpdateRN(
pack_path="Packs/HelloWorld",
update_type="minor",
modified_files_in_pack={"HelloWorld"},
added_files=set(),
)

output = update_rn.build_rn_desc(text=input_text)

assert output == expected_output, f"Expected {expected_output}, got {output}"

@pytest.mark.parametrize(
"file_type, marketplaces, expected_result, not_expected",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def update_release_notes(
None,
"-t",
"--text",
help="Text to add to all of the release notes files.",
help="Text to add to all of the release notes files, supporting special characters like \t, \n, etc.",
metavar="TEXT",
),
prev_ver: str = typer.Option(
Expand Down
3 changes: 1 addition & 2 deletions demisto_sdk/commands/update_release_notes/update_rn.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ def build_rn_desc(
:return
The release notes description
"""

text = text.encode("utf-8").decode("unicode_escape")
if self.is_force:
rn_desc = f"## {content_name}\n\n"
rn_desc += f'- {text or "%%UPDATE_RN%%"}\n'
Expand Down Expand Up @@ -792,7 +792,6 @@ def build_rn_desc(
rn_desc += deprecate_rn
else:
rn_desc += f'- {text or "%%UPDATE_RN%%"}\n'

if docker_image:
rn_desc += f"- Updated the Docker image to: *{docker_image}*.\n"
return rn_desc
Expand Down

0 comments on commit 394cbb3

Please sign in to comment.