fix: strip carapace double-backslash quoting in compadd capture - #584
Open
nirvana6 wants to merge 1 commit into
Open
fix: strip carapace double-backslash quoting in compadd capture#584nirvana6 wants to merge 1 commit into
nirvana6 wants to merge 1 commit into
Conversation
When carapace provides completions, it passes pre-quoted words to compadd with -Q using double backslash escaping (e.g., "path\\ file" instead of "path\ file"). fzf-tab's -ftb-compadd captures these words as-is, and when re-inserted with -Q, the double backslash is treated literally by zsh, causing paths with spaces to break into separate tokens. Fix: when the original compadd call used -Q, strip one level of backslash quoting from the captured word (\\ -> \), which is the format zsh expects for pre-quoted compadd -Q words. This fix only activates when -Q is present in the original args, so native zsh completions (which do not use -Q) are unaffected. Fixes: Aloxaf#503
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.
Problem
Carapace passes pre-quoted words to
compaddwith-Q, using double backslash escaping (path\\ fileinstead ofpath\ file). When fzf-tab's-ftb-compaddcaptures these words and re-inserts them with-Q, the double backslash is placed literally on the command line. Zsh parses\\as a literal backslash followed by a word boundary, breaking paths with spaces into separate tokens.Observed bug: completing a filename with spaces (e.g.,
中文 文件.txt) via carapace-accelerated fzf-tab results in中文\\ 文件.txton the command line, which zsh treats as two separate words (中文\+文件.txt) instead of one.Root Cause
In
-ftb-compadd, thewordfrom compadd arguments is stored as-is. When the original completer (carapace) uses-Qwith double-backslash escaping, the stored word contains\\. On re-insertion via_fzf-tab-apply(which preserves-Q), the double backslash is treated as literal characters.Fix
In
-ftb-compadd, after capturingword=$__hits[i], strip one level of backslash quoting when-Qwas present in the original compadd call:This converts
\\→\(two literal backslashes to one), matching the format zsh expects for pre-quotedcompadd -Qwords.Safety
-Qis in the original args — native zsh completions (_files,_path_files) do not use-Qand are unaffected\) contain no\\sequence to match\characters, carapace would escape them as\\\\(4 backslashes). Stripping\\→\converts 4→2, preserving the correct escape levelFixes #503