__fish_complete_list: only unescape "$(commandline -t)"

Commit cd3da62d24 (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.
This commit is contained in:
Johannes Altmanninger
2025-06-21 18:29:31 +02:00
parent 320ebb6859
commit 60881f1195
2 changed files with 10 additions and 3 deletions

View File

@@ -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

View File

@@ -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