From 868b296c78679032accaa31f6ec6c201359520ac Mon Sep 17 00:00:00 2001 From: mck09 Date: Fri, 14 Aug 2026 15:52:22 +0200 Subject: [PATCH] Fix the Windows check in the man page lookup `is_available()` guarded on `os.system == 'nt'`, comparing the built-in function to a string, so the branch was never taken. On Windows the lookup fell through to running `man` and only returned False because the resulting FileNotFoundError was swallowed -- where a `man` is on PATH, from Git Bash or WSL, HTTPie went on to render man pages. Use `is_windows` from `httpie.compat`, which the rest of the codebase already uses for this. --- CHANGELOG.md | 4 +++ httpie/output/ui/man_pages.py | 3 ++- tests/test_man_pages.py | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/test_man_pages.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 0497ac3508..5864b91ce8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ This document records all notable changes to [HTTPie](https://httpie.io). This project adheres to [Semantic Versioning](https://semver.org/). +## [3.2.5-dev](https://github.com/httpie/cli/compare/3.2.4...master) (unreleased) + +- Fixed the Windows check in the man page lookup, which compared `os.system` to `'nt'` and never matched. ([#1898](https://github.com/httpie/cli/issues/1898)) + ## [3.2.4](https://github.com/httpie/cli/compare/3.2.3...3.2.4) (2024-11-01) - Fix default certs loading and unpin `requests`. ([#1596](https://github.com/httpie/cli/issues/1596)) diff --git a/httpie/output/ui/man_pages.py b/httpie/output/ui/man_pages.py index 0ba4974578..78e7229524 100644 --- a/httpie/output/ui/man_pages.py +++ b/httpie/output/ui/man_pages.py @@ -2,6 +2,7 @@ import subprocess import os +from httpie.compat import is_windows from httpie.context import Environment @@ -18,7 +19,7 @@ def is_available(program: str) -> bool: Check whether `program`'s man pages are available on this system. """ - if NO_MAN_PAGES or os.system == 'nt': + if NO_MAN_PAGES or is_windows: return False try: process = subprocess.run( diff --git a/tests/test_man_pages.py b/tests/test_man_pages.py new file mode 100644 index 0000000000..1447ca0f4c --- /dev/null +++ b/tests/test_man_pages.py @@ -0,0 +1,47 @@ +import pytest + +from httpie.output.ui import man_pages + + +@pytest.fixture(autouse=True) +def enable_man_pages(mocker): + mocker.patch.object(man_pages, 'NO_MAN_PAGES', False) + mocker.patch.object(man_pages, 'is_windows', False) + + +def test_is_available_on_windows(mocker): + # see https://github.com/httpie/cli/issues/1898 + mocker.patch.object(man_pages, 'is_windows', True) + run = mocker.patch.object(man_pages.subprocess, 'run') + run.return_value.returncode = 0 + + assert man_pages.is_available('http') is False + run.assert_not_called() + + +def test_is_available_when_disabled(mocker): + mocker.patch.object(man_pages, 'NO_MAN_PAGES', True) + run = mocker.patch.object(man_pages.subprocess, 'run') + + assert man_pages.is_available('http') is False + run.assert_not_called() + + +def test_is_available_when_man_page_exists(mocker): + run = mocker.patch.object(man_pages.subprocess, 'run') + run.return_value.returncode = 0 + + assert man_pages.is_available('http') is True + + +def test_is_available_when_man_page_is_missing(mocker): + run = mocker.patch.object(man_pages.subprocess, 'run') + run.return_value.returncode = 1 + + assert man_pages.is_available('http') is False + + +def test_is_available_when_man_is_not_installed(mocker): + mocker.patch.object(man_pages.subprocess, 'run', side_effect=FileNotFoundError) + + assert man_pages.is_available('http') is False