mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
__fish_complete_suffix: Remove eval
This use of eval is unsafe, not really all that useful and can spew errors that can't be suppressed. So let's remove it, and in future add a thing that can do expansions in a safe manner Fixes #6456.
This commit is contained in:
parent
0866013280
commit
b0e3cc4b5c
@ -51,8 +51,6 @@ function __fish_complete_suffix -d "Complete using files"
|
|||||||
# Strip leading ./ as it confuses the detection of base and suffix
|
# Strip leading ./ as it confuses the detection of base and suffix
|
||||||
# It is conditionally re-added below.
|
# It is conditionally re-added below.
|
||||||
set base $prefix(string replace -r '^("\')?\\./' '' -- $comp | string trim -c '\'"') # " make emacs syntax highlighting happy
|
set base $prefix(string replace -r '^("\')?\\./' '' -- $comp | string trim -c '\'"') # " make emacs syntax highlighting happy
|
||||||
# echo "base: $base" > /dev/tty
|
|
||||||
# echo "suffix: $suff" > /dev/tty
|
|
||||||
|
|
||||||
set -l all
|
set -l all
|
||||||
set -l dirs
|
set -l dirs
|
||||||
@ -61,11 +59,10 @@ function __fish_complete_suffix -d "Complete using files"
|
|||||||
# correct form.
|
# correct form.
|
||||||
|
|
||||||
# Also do directory completion, since there might be files with the correct
|
# Also do directory completion, since there might be files with the correct
|
||||||
# suffix in a subdirectory. `eval` is used since $suff may be passed in
|
# suffix in a subdirectory.
|
||||||
# as {.foo,.bar} and we want to expand that.
|
set all $base*$suff
|
||||||
eval "set all $base*$suff"
|
|
||||||
if not string match -qr '/$' -- $suff
|
if not string match -qr '/$' -- $suff
|
||||||
eval "set dirs $base*/"
|
set dirs $base*/
|
||||||
|
|
||||||
# The problem is that we now have each directory included twice in the output,
|
# The problem is that we now have each directory included twice in the output,
|
||||||
# once as `dir` and once as `dir/`. The runtime here is O(n) for n directories
|
# once as `dir` and once as `dir/`. The runtime here is O(n) for n directories
|
||||||
@ -86,15 +83,6 @@ function __fish_complete_suffix -d "Complete using files"
|
|||||||
set files (string replace -r -- "^-" "./-" $files)
|
set files (string replace -r -- "^-" "./-" $files)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Another problem is that expanded paths are not matched, either.
|
|
||||||
# So an expression like $HOME/foo*.zip will expand to /home/rdahl/foo-bar.zip
|
|
||||||
# but that no longer matches the expression at the command line.
|
|
||||||
if string match -qr '[${}*~]' -- $comp
|
|
||||||
set -l expanded
|
|
||||||
eval "set expanded $comp"
|
|
||||||
set files (string replace -- $expanded $comp $files)
|
|
||||||
end
|
|
||||||
|
|
||||||
if set -q files[1]
|
if set -q files[1]
|
||||||
if string match -qr -- . "$desc"
|
if string match -qr -- . "$desc"
|
||||||
set desc "\t$desc"
|
set desc "\t$desc"
|
||||||
@ -104,7 +92,7 @@ function __fish_complete_suffix -d "Complete using files"
|
|||||||
# way of doing a pcre2 escape so we can use a regex replace instead
|
# way of doing a pcre2 escape so we can use a regex replace instead
|
||||||
set files (string replace $prefix "" $files)
|
set files (string replace $prefix "" $files)
|
||||||
end
|
end
|
||||||
printf "%s$desc\n" $files #| sort -u
|
printf "%s$desc\n" $files
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user