diff --git a/CHANGELOG.md b/CHANGELOG.md index 88f9743b..e7c774f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix scan progress in which all hosts are dead or excluded. [#295](https://github.com/greenbone/ospd/pull/295) - Stop all running scans before exiting [#303](https://github.com/greenbone/ospd/pull/303) - Fix start of parallel queued task. [#304](https://github.com/greenbone/ospd/pull/304) +- Strip trailing commas from the target list. [#306](https://github.com/greenbone/ospd/pull/306) ### Removed - Remove support for resume task. [#266](https://github.com/greenbone/ospd/pull/266) diff --git a/ospd/network.py b/ospd/network.py index 1d2a5ee1..d5e10758 100644 --- a/ospd/network.py +++ b/ospd/network.py @@ -279,8 +279,9 @@ def target_str_to_list(target_str: str) -> Optional[List]: if not target_str: return None - for target in target_str.split(','): + target_str = target_str.strip(',') + for target in target_str.split(','): target = target.strip() target_list = target_to_list(target) diff --git a/tests/test_target_convert.py b/tests/test_target_convert.py index 1a17c790..2d8d8128 100644 --- a/tests/test_target_convert.py +++ b/tests/test_target_convert.py @@ -49,6 +49,15 @@ def test_range(self): for i in range(1, 10): self.assertIn('195.70.81.%d' % i, addresses) + def test_target_str_with_trailing_comma(self): + addresses = target_str_to_list(',195.70.81.1,195.70.81.2,') + + self.assertIsNotNone(addresses) + self.assertEqual(len(addresses), 2) + + for i in range(1, 2): + self.assertIn('195.70.81.%d' % i, addresses) + def test_get_hostname_by_address(self): with patch.object(socket, "getfqdn", return_value="localhost"): hostname = get_hostname_by_address('127.0.0.1')