Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dist/
htmlcov/
.tox/
docs/_build/
.venv
.venv/
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Unreleased
``dict[str, Any]``.
- :class:`CompositeParamType` and the number-range base are now
generic with abstract methods.
- Refactor ``convert_type`` to extract type inference into a private
``_guess_type`` helper, and add :func:`typing.overload` signatures.
:pr:`3372`
- :class:`Parameter` typing improvements. :pr:`2805`

- :class:`Parameter` is now an abstract base class, making explicit
Expand Down Expand Up @@ -46,7 +49,7 @@ Unreleased
replacing the ``start`` built-in which cannot be invoked without
``shell=True``. :issue:`3164` :pr:`3186`
- Fix Fish shell completion errors when option help text contains newlines.
:issue:`3043`
:issue:`3043` :pr:`3126`
- Add :class:`NoSuchCommand` exception with suggestions for misspelled
commands. :issue:`3107` :pr:`3228`

Expand Down
17 changes: 9 additions & 8 deletions src/click/shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,16 @@ def get_completion_args(self) -> tuple[list[str], str]:
return args, incomplete

def format_completion(self, item: CompletionItem) -> str:
"""Format completion item for Fish shell.

Escapes newlines in both value and help text to prevent
Fish shell parsing errors.

.. versionchanged:: 8.3
Escape newlines in help text to fix completion errors
with multi-line help strings.
"""
.. versionchanged:: 8.4
Escape newlines in value and help to fix completion errors with
multi-line help strings.
"""
# The fish completion script splits each response line on literal
# newlines, so any newline in the value or help would corrupt the
# frame. Replace them with the two-character escape "\n" so the text
# round-trips through fish without breaking the format. The "_"
# sentinel for missing help mirrors :class:`ZshComplete`.
help_ = item.help or "_"
value = item.value.replace("\n", r"\n")
help_escaped = help_.replace("\n", r"\n")
Expand Down