Skip to content

Commit

Permalink
Merge pull request #1006 from blacklanternsecurity/improve-chained-li…
Browse files Browse the repository at this point in the history
…sts-helper

Improve chained lists helper
  • Loading branch information
TheTechromancer authored Jan 18, 2024
2 parents 9338bc6 + 66a28f2 commit 61e556a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bbot/core/helpers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,8 @@ def chain_lists(l, try_files=False, msg=None, remove_blank=True):
This function takes a list `l` and flattens it by splitting its entries on commas.
It also allows you to optionally open entries as files and add their contents to the list.
The order of entries is preserved, and deduplication is performed automatically.
Args:
l (list): The list of strings to chain together.
try_files (bool, optional): Whether to try to open entries as files. Defaults to False.
Expand All @@ -1181,6 +1183,8 @@ def chain_lists(l, try_files=False, msg=None, remove_blank=True):
>>> chain_lists(["a,file.txt", "c,d"], try_files=True)
['a', 'f_line1', 'f_line2', 'f_line3', 'c', 'd']
"""
if isinstance(l, str):
l = [l]
final_list = dict()
for entry in l:
for s in entry.split(","):
Expand Down
1 change: 1 addition & 0 deletions bbot/test/test_step_1/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ async def test_helpers_misc(helpers, scan, bbot_scanner, bbot_config, bbot_https
assert "asdf" in helpers.str_or_file(str(test_file))
assert "nope" in helpers.str_or_file("nope")
assert tuple(helpers.chain_lists([str(test_file), "nope"], try_files=True)) == ("asdf", "fdsa", "nope")
assert tuple(helpers.chain_lists("one, two", try_files=True)) == ("one", "two")
assert test_file.is_file()

with pytest.raises(DirectoryCreationError, match="Failed to create.*"):
Expand Down

0 comments on commit 61e556a

Please sign in to comment.