Skip to content

Commit

Permalink
Fix iterator vs list bug for py2/3
Browse files Browse the repository at this point in the history
  • Loading branch information
gwillem committed Feb 23, 2018
1 parent 2570f8e commit fcda7b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions mwscan/scan.py
Expand Up @@ -150,8 +150,11 @@ def find_targets(root_path, required_extensions=None,
if required_extensions and myfile.split('.')[-1] not in required_extensions:
continue

if os.path.islink(path) and not follow_symlinks:
continue
if os.path.islink(path):
if not follow_symlinks:
continue
if not os.path.exists(path):
continue

if [x for x in exclude_patterns if re.search(x, path)]:
continue
Expand Down
10 changes: 8 additions & 2 deletions mwscan/tests/test_mwscan.py
Expand Up @@ -85,9 +85,15 @@ def test_find_targets_will_exclude_patterns(self):
files = list(scan.find_targets(self.target_path, exclude_patterns=p))
assert files == [], files

def test_that_symlinks_are_followed(self):
def test_that_symlinks_are_properly_followed(self):
paths = scan.find_targets(self.target_path, follow_symlinks=True)
files = map(os.path.basename, paths)
files = list(map(os.path.basename, paths))


# py3 returns map whereas py2 returns list,
# map can only be iterated once
assert len(files) > 5, 'bogus files obj'

assert 'im_a_symlink' in files, \
'no symlink found in results'
assert 'recursive_symlink' not in files, \
Expand Down

0 comments on commit fcda7b0

Please sign in to comment.