Escape backslashes in fish completion descriptions#536
Open
greymoth-jp wants to merge 1 commit into
Open
Conversation
The fish completions generator escapes single quotes in descriptions but leaves backslashes untouched. Since a backslash inside fish single quotes still escapes the next character, a doubled backslash collapses and a trailing backslash escapes the closing quote, breaking the generated completion line. Escape backslashes first, as the zsh path already does.
15101ac to
0eb0722
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The fish completions generator escapes single quotes in each option and command description, but leaves backslashes untouched:
The result is emitted inside a single-quoted fish argument,
-d '<description>'. Single quotes in fish are not fully literal: per the language docs, "the only meaningful escape sequences in single quotes are\', which escapes a single quote and\, which escapes the backslash symbol." So a backslash in a description is mishandled:completeline.The zsh path already accounts for this.
_zsh_describeescapes backslashes (they are part of the character class it passes throughre.sub), so the fish path is the odd one out.The fix escapes backslashes before single quotes, matching the order zsh already uses:
I added a regression test that renders a fish completion for a command whose description contains a backslash and a single quote, and checks that both are escaped. Reverting the one-line change makes it fail. The full test suite passes and
ruff check/ruff formatare clean.