diff options
author | Louis Sautier <sautier.louis@gmail.com> | 2021-02-28 17:50:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-28 17:50:05 +0100 |
commit | cc8d9185d1b0ca79ed49efd0ee2d3cae5b1cacbb (patch) | |
tree | f7b9eea94aacd3a80bbcaaf1837ea75c3d77fea4 | |
parent | 41d2349c7b84714539a9979b5344294029c984ab (diff) | |
download | pylint-git-cc8d9185d1b0ca79ed49efd0ee2d3cae5b1cacbb.tar.gz |
Properly strip dangerous sys.path entries (not just the first one) (#4153)
51c646bf70a6e0a86492bfd2ddd1885671d64d67 only stripped the first bad
sys.path entry, causing problems when PYTHONPATH starts or ends with a
colon.
Closes: https://github.com/PyCQA/pylint/issues/3636
-rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | pylint/__main__.py | 3 | ||||
-rw-r--r-- | tests/test_self.py | 18 |
4 files changed, 24 insertions, 2 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 2b0cf022b..197b8da9f 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -452,3 +452,5 @@ contributors: * Tiago Honorato: contributor * Lefteris Karapetsas: contributor + +* Louis Sautier: contributor @@ -15,6 +15,9 @@ What's New in Pylint 2.7.2? * Fix False Positive on `Enum.__members__.items()`, `Enum.__members__.values`, and `Enum.__members__.keys` Closes #4123 +* Properly strip dangerous sys.path entries (not just the first one) + + Closes #3636 What's New in Pylint 2.7.1? =========================== diff --git a/pylint/__main__.py b/pylint/__main__.py index 767746a2a..89bd19924 100644 --- a/pylint/__main__.py +++ b/pylint/__main__.py @@ -13,7 +13,6 @@ import pylint # inadvertently import user code from modules having the same name as # stdlib or pylint's own modules. # CPython issue: https://bugs.python.org/issue33053 -if sys.path[0] == "" or sys.path[0] == os.getcwd(): - sys.path.pop(0) +sys.path = [p for p in sys.path if p not in ("", os.getcwd())] pylint.run_pylint() diff --git a/tests/test_self.py b/tests/test_self.py index 27bb342ab..8b243d2e9 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -716,6 +716,24 @@ class TestRunTC: cwd=str(tmpdir), ) + # Appending a colon to PYTHONPATH should not break path stripping + # https://github.com/PyCQA/pylint/issues/3636 + with tmpdir.as_cwd(): + orig_pythonpath = os.environ.get("PYTHONPATH") + os.environ["PYTHONPATH"] = os.environ.get("PYTHONPATH", "") + ":" + subprocess.check_output( + [ + sys.executable, + "-m", + "pylint", + "astroid.py", + "--disable=import-error,unused-import", + ], + cwd=str(tmpdir), + ) + if orig_pythonpath is not None: + os.environ["PYTHONPATH"] = orig_pythonpath + # Linting this astroid file does not import it with tmpdir.as_cwd(): subprocess.check_output( |