Skip to content

🐛 Fix Rich emoji shortcodes in zsh completion help text - #1988

Open
b1ackout wants to merge 1 commit into
fastapi:masterfrom
b1ackout:b1ackout-fix/zsh-completion-rich-markup
Open

b1ackout wants to merge 1 commit into
fastapi:masterfrom
b1ackout:b1ackout-fix/zsh-completion-rich-markup

Conversation

@b1ackout

@b1ackout b1ackout commented Oct 27, 2026 •

Copy link
Copy Markdown

Summary

  • render the help text with Rich before escaping it in ZshComplete.format_completion
  • keep escaping colons in plain help text
  • add regression tests for emoji shortcodes and plain colons

Problem

ZshComplete.format_completion escapes : to \\: (as zsh's _describe requires) before the help text is rendered by Rich.

Rich then no longer recognises emoji shortcodes such as :warning:, so the escaped text is shown literally in the zsh completion list instead of the emoji.

Fix

The help text is now passed through _sanitize_help_text() first, and the rendered result is escaped, so there is nothing left for the escaping to break.

Colons in plain help text (e.g. Note: careful) are still escaped. Bash, fish and PowerShell completion are unchanged.

Tests

Added to tests/test_completion/test_sanitization.py:

  • an emoji shortcode with Rich markup is rendered (:warning: Spin up [bold]now[/bold] -> ⚠ Spin up now)
  • colons in plain help text are still escaped

The emoji case fails without the fix.

Validation results:

  • tests/test_completion and tests/test_others.py: 107 passed, 8 skipped
  • scripts/lint.sh and scripts/test.sh passed

@chrikrah chrikrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing here blocks a merge from my side, @b1ackout. Swapping the order only changes help text that Rich rewrites. Fish and PowerShell pass help to Rich without escaping it, so zsh was the only shell where escaping ran before rendering.

$ python -m pytest tests/test_completion -q   # head 4eb4b89, CPython 3.12, rich installed
79 passed, 7 skipped in 48.76s

# typer/_completion_classes.py from a5882de, tests kept
$ python -m pytest tests/test_completion/test_sanitization.py -q
FAILED ...test_zsh_format_completion_renders_help_before_escaping[:warning: Spin up [bold]now[/bold]-...]
1 failed, 5 passed in 0.22s

# probe: ZshComplete.format_completion on help with $, backticks, quotes, a backslash, "1:2:3" and "\[literal]"
# all five print byte-identical output at a5882de and 4eb4b89
$ ruff check typer/_completion_classes.py tests/test_completion/test_sanitization.py   # ruff 0.17.3
All checks passed!
# not run: a live zsh session, the full suite

Would one of those probe cases be worth adding to the parametrize list, so the next change to escape() has a guard for $ too?

@svlandeg svlandeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While this fix might be worthwile reviewing, it would have been nice @b1ackout if you would adhere to the contribution guidelines 🙏 (i.e. discussion first, disclose AI usage, etc).

This branch has not been deployed

No deployments
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.

4 participants