From 4cb1dc8c44ad2e891f1b8c8c7d774353311e7b06 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 5 Jan 2022 11:44:31 -0500 Subject: [PATCH] perform path normalization on '.' --- src/flake8/utils.py | 8 +++++--- tests/unit/test_utils.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/flake8/utils.py b/src/flake8/utils.py index a5a1901..bbc89a1 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -177,13 +177,15 @@ def normalize_path(path: str, parent: str = os.curdir) -> str: str """ # NOTE(sigmavirus24): Using os.path.sep and os.path.altsep allow for - # Windows compatibility with both Windows-style paths (c:\\foo\bar) and + # Windows compatibility with both Windows-style paths (c:\foo\bar) and # Unix style paths (/foo/bar). separator = os.path.sep # NOTE(sigmavirus24): os.path.altsep may be None alternate_separator = os.path.altsep or "" - if separator in path or ( - alternate_separator and alternate_separator in path + if ( + path == "." + or separator in path + or (alternate_separator and alternate_separator in path) ): path = os.path.abspath(os.path.join(parent, path)) return path.rstrip(separator + alternate_separator) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 167ba72..5aadf2f 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -132,6 +132,7 @@ def test_invalid_file_list(value): "value,expected", [ ("flake8", "flake8"), + (".", os.path.abspath(".")), ("../flake8", os.path.abspath("../flake8")), ("flake8/", os.path.abspath("flake8")), ],