Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/specify_cli/integrations/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Callable

import typer
from rich.markup import escape

from .._agent_config import SCRIPT_TYPE_CHOICES
from .._console import console
Expand Down Expand Up @@ -206,7 +207,7 @@ def _parse_integration_options(integration: Any, raw_options: str) -> dict[str,
while i < len(tokens):
token = tokens[i]
if not token.startswith("-"):
console.print(f"[red]Error:[/red] Unexpected integration option value '{token}'.")
console.print(f"[red]Error:[/red] Unexpected integration option value '{escape(token)}'.")
if allowed:
console.print(f"Allowed options: {allowed}")
raise typer.Exit(1)
Expand All @@ -217,7 +218,7 @@ def _parse_integration_options(integration: Any, raw_options: str) -> dict[str,
name, value = name.split("=", 1)
opt = declared.get(name)
if not opt:
console.print(f"[red]Error:[/red] Unknown integration option '{token}'.")
console.print(f"[red]Error:[/red] Unknown integration option '{escape(token)}'.")
if allowed:
console.print(f"Allowed options: {allowed}")
raise typer.Exit(1)
Expand Down
24 changes: 24 additions & 0 deletions tests/integrations/test_integration_subcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,30 @@ def test_unbalanced_quote_exits_cleanly(self, capsys):
assert excinfo.value.exit_code == 1
assert "Error: Could not parse integration options: No closing quotation." in capsys.readouterr().out

def test_bad_option_token_with_rich_markup_exits_cleanly(self):
"""A bad option token carrying Rich markup must exit cleanly, not crash.

The token is user-controlled and gets interpolated into console.print.
A value like '[/red]foo' parses fine through shlex but is an unexpected
value / unknown option — and an unbalanced Rich tag would raise
rich.errors.MarkupError inside console.print, leaking a traceback
instead of the intended typer.Exit(1). The token must be escaped."""
import typer

from specify_cli.integrations._commands import _parse_integration_options
from specify_cli.integrations import get_integration

integration = get_integration("generic")
assert integration is not None

# Unexpected value token carrying markup.
with pytest.raises(typer.Exit):
_parse_integration_options(integration, "[/red]foo")

# Unknown option token carrying markup.
with pytest.raises(typer.Exit):
_parse_integration_options(integration, "--[/red]bad")


class TestUninstallNoManifestClearsInitOptions:
def test_init_options_cleared_on_no_manifest_uninstall(self, tmp_path):
Expand Down