Escape backslashes in fish completion descriptions#2378
Open
greymoth-jp wants to merge 1 commit into
Open
Conversation
Inside a fish single-quoted string a literal backslash must be written as a doubled backslash, just as a literal single quote is written as backslash plus quote. escapeSingleQuotes only handled the quote, so a usage string containing a backslash corrupted the generated -d '...' description, and a trailing backslash left the single-quoted string unterminated. See https://fishshell.com/docs/current/language.html
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.
What type of PR is this?
bug
What this PR does / why we need it:
ToFishCompletionwrites flag and command descriptions into fish-d '...'tokens and escapes them withescapeSingleQuotes. That helper only replaced'with\'and left backslashes untouched.Inside a fish single-quoted string the only escape sequences are
\\and\'(https://fishshell.com/docs/current/language.html). An unescaped backslash in a usage string is therefore mis-parsed:\'), so the description is never terminated and the rest of the script is swallowed. A usage ofC:\tmp\was emitted as-d 'C:\tmp\'.\\servercollapsed down to a single one.This escapes the backslash as
\\in addition to the existing single-quote handling.fish.go:escapeSingleQuotesnow doubles backslashes as well as escaping single quotes, using astrings.Replacer.fish_test.go: addsTestFishCompletionBackslashEscaping, covering a flag and a subcommand whose usage contains backslashes.Usage strings without backslashes are unaffected, so existing output (including
testdata/expected-fish-full.fish) is unchanged.Which issue(s) this PR fixes:
NONE
Testing
go test ./...passes. The new test fails before the change, where the descriptions are emitted with single, unescaped backslashes, and passes after it.Release Notes