Skip to content

fix(integrations): exit cleanly on malformed --integration-options quoting#3458

Open
Quratulain-bilal wants to merge 2 commits into
github:mainfrom
Quratulain-bilal:fix/integration-options-shlex
Open

fix(integrations): exit cleanly on malformed --integration-options quoting#3458
Quratulain-bilal wants to merge 2 commits into
github:mainfrom
Quratulain-bilal:fix/integration-options-shlex

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

fixes #3457

_parse_integration_options called shlex.split(raw_options) unguarded. an unbalanced quote in the flag value (e.g. --integration-options='--commands-dir "foo') makes shlex raise ValueError: No closing quotation, so a raw traceback escaped instead of the typer.Exit(1) error every other bad-input path in this function produces (unknown option, missing value, unexpected value). reachable from specify init and every integration install/switch/upgrade/migrate that accepts --integration-options.

fix: wrap the shlex.split in try/except and convert ValueError into the same clean one-line CLI error + exit 1.

added a regression test (test_malformed_quoting_exits_cleanly) asserting a typer.Exit on an unbalanced quote. i confirmed it fails on the pre-fix code by stashing the source and re-running (raw ValueError: No closing quotation); the parse-options tests pass with the fix.

note: i used an ai assistant to help investigate and write this up.

…oting

_parse_integration_options called shlex.split(raw_options) unguarded. an
unbalanced quote (e.g. --integration-options='--commands-dir "foo') makes
shlex raise ValueError('No closing quotation'), so a raw traceback escaped
instead of the typer.Exit(1) error every other bad-input path in this function
produces. reachable from specify init and every integration install/switch/
upgrade/migrate that accepts --integration-options.

wrap the split and convert ValueError into the same clean CLI error. added a
regression test; confirmed it fails on the pre-fix code (raw ValueError).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Handles malformed integration-option quoting without exposing ValueError tracebacks.

Changes:

  • Converts shlex.split failures into typer.Exit(1).
  • Adds regression coverage for unbalanced quotes.
Show a summary per file
File Description
src/specify_cli/integrations/_helpers.py Handles malformed quoting during option parsing.
tests/integrations/test_integration_subcommand.py Tests clean failure on unbalanced quotes.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment on lines +201 to +202
f"[red]Error:[/red] Could not parse integration options "
f"'{raw_options}': {error}."

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback

the malformed-quoting handler (and the unexpected/unknown option
branches) interpolate raw_options/token into console.print. a value
carrying an unbalanced rich tag like '--commands-dir "[/red]foo' first
trips the intended shlex ValueError, but the error print then raises
rich.errors.MarkupError and leaks a traceback anyway. escape all three
before printing so the clean typer.Exit survives.

added a regression covering both the shlex path and a bare markup token.
@Quratulain-bilal

Quratulain-bilal commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

escaped the value before interpolating it in aa810ba — you're right that --commands-dir "[/red]foo tripped the intended ValueError but then the error print itself raised MarkupError on the unbalanced tag and leaked a traceback anyway.

swept the two sibling branches in the same function too (the 'unexpected option value' and 'unknown option' prints both interpolate the raw token), since a bare [/red]foo token would hit the same wall without an unbalanced quote.

regression covers both: an unbalanced-quote value carrying markup, and a plain markup token. confirmed both raise MarkupError on the pre-fix code and exit cleanly with the escape.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@mnriem

mnriem commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Please resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--integration-options with an unbalanced quote crashes with a raw ValueError

3 participants