Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
Strip trailing commas from the target list
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Jul 27, 2020
1 parent e1cd393 commit 4a7724a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion ospd/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_target_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 4a7724a

Please sign in to comment.