Skip to content

Commit 5563ae6

Browse files
dukecat0uranusjrpre-commit-ci[bot]
authored
Verify if script name provided is a file before running it (#1155)
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9956f7a commit 5563ae6

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Update `pipx run` on scripts using `/// script` and no `run` table following the updated version of PEP 723 (#1180)
66
- Avoid repeated exception logging in a few rare cases (#1192)
77
- Include `tomli` into `pipx.pyz` (zipapp) so that it can be executed with Python 3.10 or earlier (#1142)
8+
- `pipx run`: Verify whether the script name provided is a file before running it
89

910
## 1.4.1
1011

src/pipx/commands/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def maybe_script_content(app: str, is_path: bool) -> Optional[str]:
4848

4949
# Look for a local file first.
5050
app_path = Path(app)
51-
if app_path.exists():
51+
if app_path.is_file():
5252
return app_path.read_text(encoding="utf-8")
5353
elif is_path:
5454
raise PipxError(f"The specified path {app} does not exist")

tests/test_run.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ def test_run_with_windows_python_version(caplog, pipx_temp_env, tmp_path):
355355
assert "3.12" in out.read_text()
356356

357357

358+
@mock.patch("os.execvpe", new=execvpe_mock)
359+
def test_run_verify_script_name_provided(pipx_temp_env, capsys, tmpdir):
360+
tmpdir.mkdir("black")
361+
run_pipx_cli_exit(["run", "black"])
362+
captured = capsys.readouterr()
363+
assert "black" in captured.err
364+
365+
358366
@mock.patch("os.execvpe", new=execvpe_mock)
359367
def test_run_shared_lib_as_app(pipx_temp_env, monkeypatch, capfd):
360368
run_pipx_cli_exit(["run", "pip", "--help"])

0 commit comments

Comments
 (0)