Skip to content

Commit ddf20d0

Browse files
committed
Add changelog entry, fix admonition and add test
1 parent b7e5fd4 commit ddf20d0

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Version 8.4.2
55

66
Unreleased
77

8+
- Fix Fish shell completion broken in ``8.4.0`` by :pr:`3126`. Newlines and
9+
tabs in option help text are now escaped, keeping the original completion
10+
format while still supporting multi-line help. :issue:`3502`
11+
:issue:`3043` :pr:`3504` :pr:`3508`
12+
813

914
Version 8.4.1
1015
-------------

src/click/shell_completion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ def get_completion_args(self) -> tuple[list[str], str]:
419419

420420
def format_completion(self, item: CompletionItem) -> str:
421421
"""
422-
.. versionchanged:: 8.4.0
423-
Escape newlines in value and help to fix completion errors with
424-
multi-line help strings.
422+
.. versionchanged:: 8.4.2
423+
Escape newlines and replace tabs with spaces in the help text to
424+
fix completion errors with multi-line help strings.
425425
"""
426426
# According to https://fishshell.com/docs/current/cmds/complete.html
427427
# Command substitutions found in ARGUMENTS should return a newline-

tests/test_shell_completion.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from click.core import Option
1313
from click.shell_completion import add_completion_class
1414
from click.shell_completion import CompletionItem
15+
from click.shell_completion import FishComplete
1516
from click.shell_completion import shell_complete
1617
from click.shell_completion import ShellComplete
1718
from click.types import Choice
@@ -576,3 +577,11 @@ def cli(ctx, config_file):
576577
assert not current_warnings, "There should be no warnings to start"
577578
_get_completions(cli, args=[], incomplete="")
578579
assert not current_warnings, "There should be no warnings after either"
580+
581+
582+
def test_fish_format_completion_escapes_help():
583+
fc = FishComplete(Command("x"), {}, "x", "_X_COMPLETE")
584+
item = CompletionItem("--at", help="first\nsecond\tthird")
585+
# The newline is escaped to the literal characters backslash-n and the tab
586+
# becomes a space, so each completion stays on one line for fish.
587+
assert fc.format_completion(item) == "plain,--at\tfirst\\nsecond third"

0 commit comments

Comments
 (0)