From 60881f11959d2af067612e33c09e6db2e65dd38d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 21 Jun 2025 18:29:31 +0200 Subject: [PATCH] __fish_complete_list: only unescape "$(commandline -t)" Commit cd3da62d244 (fix(completion): unescape strings for __fish_complete_list, 2024-09-17) bravely addressed an issue that exists in a lot of completions. It did so only for __fish_complete_list. Fair enough. Unfortunately it unescaped more than just "$(commandline -t)". This causes the problem described at https://github.com/fish-shell/fish-shell/issues/11508#issuecomment-2889088934 where completion descriptions containing a backslash followed by "n" are interpreted as newlines, breaking the completion parser. Fix that. --- share/functions/__fish_complete_list.fish | 6 +++--- tests/checks/complete.fish | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/share/functions/__fish_complete_list.fish b/share/functions/__fish_complete_list.fish index 758489572..b2e5c88f3 100644 --- a/share/functions/__fish_complete_list.fish +++ b/share/functions/__fish_complete_list.fish @@ -19,12 +19,12 @@ where: end switch $pat case "*$div*" - for i in (echo $pat | sed "s/^\(.\+$div\)$iprefix.*\$/\1/")$iprefix(eval $cmd) - string unescape -- $i + for i in (string unescape -- $pat | sed "s/^\(.\+$div\)$iprefix.*\$/\1/")$iprefix(eval $cmd) + printf %s\n $i end case '*' for i in $prefix$iprefix(eval $cmd) - string unescape -- $i + printf %s\n $i end end diff --git a/tests/checks/complete.fish b/tests/checks/complete.fish index 739d675e6..f90b98aab 100644 --- a/tests/checks/complete.fish +++ b/tests/checks/complete.fish @@ -647,3 +647,10 @@ complete -C "complete-list --number-list=1," complete -C "complete-list -abcl1," # CHECK: -abcl1,1 # CHECK: -abcl1,2 + +function esc_in_description + echo completion\t'escaped \n newline' +end +complete complete-list -l desc -xa '(__fish_complete_list , esc_in_description)' +complete -C 'complete-list --desc ' +# CHECK: completion{{\t}}escaped {{\\n}} newline