From 4e00450d2bbfbc0513dc1050f4831ae36f43d948 Mon Sep 17 00:00:00 2001 From: Rico Date: Wed, 16 Sep 2020 20:26:55 +0200 Subject: [PATCH] refactor: improve string concatenation for templatingengine --- pastepwn/util/templatingengine.py | 4 +--- pastepwn/util/tests/templatingengine_test.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pastepwn/util/templatingengine.py b/pastepwn/util/templatingengine.py index 25b4690..bbb6366 100644 --- a/pastepwn/util/templatingengine.py +++ b/pastepwn/util/templatingengine.py @@ -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 diff --git a/pastepwn/util/tests/templatingengine_test.py b/pastepwn/util/tests/templatingengine_test.py index ab92407..6f20993 100644 --- a/pastepwn/util/tests/templatingengine_test.py +++ b/pastepwn/util/tests/templatingengine_test.py @@ -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!")