Skip to content

Bug: Windows guard in is_available() compares os.system (a function) to 'nt' — always False #1898

Description

@truongsontung

Description

In httpie/output/ui/man_pages.py, is_available() tries to short-circuit on Windows but the check is broken:

https://github.com/httpie/cli/blob/master/httpie/output/ui/man_pages.py#L21

def is_available(program: str) -> bool:
    if NO_MAN_PAGES or os.system == 'nt':
        return False
    ...

os.system is a built-in function object, so os.system == 'nt' is always False. The intended Windows guard never fires. The author almost certainly meant os.name == 'nt'.

Why it is wrong

  • os.system is <built-in function system>; comparing a callable to the string 'nt' is always False.
  • The correct, idiomatic Windows check is os.name == 'nt' (or sys.platform == 'win32').

Impact

On Windows the if NO_MAN_PAGES or os.system == 'nt': branch is dead code. The function does not short-circuit; instead it falls through to subprocess.run(['man', '1', program]). On a typical Windows install man is absent, so FileNotFoundError is raised and swallowed by the except Exception: return False, yielding the same observable result — but only by accident. If a man executable happens to be on PATH (e.g. Git Bash / WSL), HTTPie will attempt to render man pages on Windows, contrary to the intent of the guard. Also, relying on a swallowed exception for control flow is fragile.

Reproduction / verification

import os
print(os.system == 'nt')   # -> False (regardless of platform)
print(os.name == 'nt')     # -> True on Windows, 'posix' elsewhere

Suggested fix

import sys
...
def is_available(program: str) -> bool:
    if NO_MAN_PAGES or sys.platform == 'win32':
        return False
    ...

(Using sys.platform == 'win32' is the most robust Windows detector.)

Affected version

Current master (verified via git clone --depth 1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions