diff --git a/bandit/core/utils.py b/bandit/core/utils.py index d637a6b2..a16f5642 100644 --- a/bandit/core/utils.py +++ b/bandit/core/utils.py @@ -151,7 +151,7 @@ def get_module_qualname_from_path(path): ' Missing path or file name' % (path)) qname = [os.path.splitext(tail)[0]] - while head not in ['/', '.']: + while head not in ['/', '.', '']: if os.path.isfile(os.path.join(head, '__init__.py')): (head, tail) = os.path.split(head) qname.insert(0, tail) diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/init-py-test/__init__.py b/examples/init-py-test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/init-py-test/subdirectory-okay.py b/examples/init-py-test/subdirectory-okay.py new file mode 100644 index 00000000..8feea28a --- /dev/null +++ b/examples/init-py-test/subdirectory-okay.py @@ -0,0 +1,3 @@ +# A sample test file in a subdirectory and its parents both containing +# an __init__.py file outlined in bug/1743042. +print('hopefully no vulnerabilities here') diff --git a/setup.cfg b/setup.cfg index 100b6ce6..ddd7b9ae 100644 --- a/setup.cfg +++ b/setup.cfg @@ -121,6 +121,8 @@ source-dir = doc/source [pbr] autodoc_tree_index_modules = True +autodoc_tree_excludes = + examples* [bdist_wheel] universal = 1 diff --git a/tests/functional/test_functional.py b/tests/functional/test_functional.py index 58ec5996..3b1f475c 100644 --- a/tests/functional/test_functional.py +++ b/tests/functional/test_functional.py @@ -285,6 +285,14 @@ class FunctionalTests(testtools.TestCase): } self.check_example('okay.py', expect) + def test_subdirectory_okay(self): + '''Test a vulnerability-free file under a subdirectory.''' + expect = { + 'SEVERITY': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 0}, + 'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 0} + } + self.check_example('init-py-test/subdirectory-okay.py', expect) + def test_os_chmod(self): '''Test setting file permissions.''' filename = 'os-chmod-{}.py'