diff --git a/src/flake8/utils.py b/src/flake8/utils.py index 29df9bc..e0c221a 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -448,7 +448,7 @@ def matches_filename(path, patterns, log_message, logger): if not patterns: return False basename = os.path.basename(path) - if fnmatch(basename, patterns): + if basename not in {".", ".."} and fnmatch(basename, patterns): logger.debug(log_message, {"path": basename, "whether": ""}) return True diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 803d643..c84a03b 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1,4 +1,5 @@ """Tests for flake8's utils module.""" +import logging import os import mock @@ -296,3 +297,10 @@ MULTI_FILE_INFO = { def test_parse_unified_diff(diff, parsed_diff): """Verify that what we parse from a diff matches expectations.""" assert utils.parse_unified_diff(diff) == parsed_diff + + +def test_matches_filename_for_excluding_dotfiles(): + """Verify that `.` and `..` are not matched by `.*`.""" + logger = logging.Logger(__name__) + assert not utils.matches_filename('.', ('.*',), '', logger) + assert not utils.matches_filename('..', ('.*',), '', logger)