Skip to content

Commit

Permalink
refactor: improve string concatenation for templatingengine
Browse files Browse the repository at this point in the history
  • Loading branch information
d-Rickyy-b committed Sep 16, 2020
1 parent c251b34 commit 4e00450
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions pastepwn/util/templatingengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ def fill_template(paste, analyzer_name, template_string, matches=None, **kwargs)
paste_dict["matches"] = ""
else:
# When there are elements in the matches object, we want them to be formatted as single string
matches_str = ""
for element in matches:
matches_str += "{}\n".format(element)
matches_str = "\n".join(matches)
paste_dict["matches"] = matches_str

# Possibility to insert own/custom values into the paste_dict thus gives more control over the template string
Expand Down
2 changes: 1 addition & 1 deletion pastepwn/util/tests/templatingengine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_fill_template(self):
def test_fill_template_matches(self):
"""Checks if templating engine inserts the matches correctly into the template"""
template = "Matches are: ${matches}"
expected = "Matches are: +123456789\n+987654321\n"
expected = "Matches are: +123456789\n+987654321"
matches = ["+123456789", "+987654321"]
result = TemplatingEngine.fill_template(paste=self.paste, analyzer_name=None, template_string=template, matches=matches)
self.assertEqual(expected, result, msg="Filled template string is not the same as the expected result!")
Expand Down

0 comments on commit 4e00450

Please sign in to comment.