fix(cli): escape quotes in generated completion descriptions - #7173
Open
dv-waynehaffenden wants to merge 1 commit into
Open
fix(cli): escape quotes in generated completion descriptions#7173dv-waynehaffenden wants to merge 1 commit into
dv-waynehaffenden wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 73210ec The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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 happened
Subcommand descriptions are interpolated into single-quoted strings in the generated zsh and fish scripts, unescaped. A description containing an apostrophe closes the string early, so the rest of the description — and then the generated script itself — comes back as completion candidates.
From a real CLI (
packages/cliat 0.77.0),commandDescriptor.tsproduced:The quote closes at
platform. In the shell,lens <TAB>then offered individual words from the descriptions (the,named,just,message,onto) alongside fragments of the script's own source (commands commands "$@",_describe -t commands lens). Completions for a prefix that resolved before the first affected element still worked, which is what made it look intermittent.zsh -ndoes not catch it: the quotes re-balance across elements, so the file is valid zsh that means something else.The fix
options.tsalready has anescapehelper for option specs, but the subcommand path incommandDescriptor.tshas none. Added a minimal one for the two sites that interpolate a description into a single-quoted string:getZshCompletionsInternal— the'name:description'entries passed to_describegetFishCompletionsInternal— the-d 'description'argument tocompleteIt escapes quotes only.
options.ts'sescapealso handles[,]and:, which are delimiters in an option spec but plain text in these two positions — escaping them here would render visible backslashes in the description a user reads.'→'\''closes the string, escapes the quote and reopens; both zsh and fish accept it. Verified in zsh that the escaped form parses as one element with the apostrophe intact:Tests
Two cases under
Completions, covering a subcommand described asClear the project's cachein each shell: the escaped sequence is present and the rawproject's cacheis absent.Disclosure
I could not run the package's test suite locally — this was a sparse checkout without a workspace install, so both changed files were only parse-checked. The assertions were derived by computing the generator's actual output for that input rather than by running vitest, so CI is the first full run.