mirror of
https://github.com/fish-shell/fish-shell
synced 2024-09-22 23:42:00 +00:00
abbr: Ensure we don't split on "=" if the given separator is " "
This fails on e.g. an abbr that uses `env a=b`, like the included test demonstrates. Unfortunately it decreases the speed again (2s vs 2.2s vs 4s original), but correctness is more important.
This commit is contained in:
parent
fdb2559425
commit
ed1919b266
2 changed files with 18 additions and 12 deletions
|
@ -157,18 +157,20 @@ function __fish_abbr_parse_entry -S -a __input __key __value
|
||||||
if test -z "$__value"
|
if test -z "$__value"
|
||||||
set __value __
|
set __value __
|
||||||
end
|
end
|
||||||
switch $__input
|
# A "=" _before_ any space - we only read the first possible separator
|
||||||
case "*=*"
|
# because the key can contain neither spaces nor "="
|
||||||
# No need for bounds-checking because we already matched before
|
if string match -qr '^[^ ]+=' -- $__input
|
||||||
set -l KV (string split "=" -m 1 -- $__input)
|
# No need for bounds-checking because we already matched before
|
||||||
set $__key $KV[1]
|
set -l KV (string split "=" -m 1 -- $__input)
|
||||||
set $__value $KV[2]
|
set $__key $KV[1]
|
||||||
case "* *"
|
set $__value $KV[2]
|
||||||
set -l KV (string split " " -m 1 -- $__input)
|
else if string match -qr '^[^ ]+ .*' -- $__input
|
||||||
set $__key $KV[1]
|
set -l KV (string split " " -m 1 -- $__input)
|
||||||
set $__value $KV[2]
|
set $__key $KV[1]
|
||||||
case "*"
|
set $__value $KV[2]
|
||||||
set $__key $__input
|
else
|
||||||
|
# This is needed for `erase` et al, where we want to allow passing a value
|
||||||
|
set $__key $__input
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,3 +31,7 @@ abbr -e '~__abbr2'
|
||||||
abbr -- '--__abbr3' 'xyz'
|
abbr -- '--__abbr3' 'xyz'
|
||||||
abbr | grep __abbr3
|
abbr | grep __abbr3
|
||||||
abbr -e '--__abbr3'
|
abbr -e '--__abbr3'
|
||||||
|
|
||||||
|
# Ensure we are not recognizing later "=" as separators
|
||||||
|
abbr d2 env a=b banana
|
||||||
|
abbr -l | string match -q d2; or echo "= test failed"
|
||||||
|
|
Loading…
Reference in a new issue