aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--share/functions/abbr.fish26
-rw-r--r--tests/abbr.in4
2 files changed, 18 insertions, 12 deletions
diff --git a/share/functions/abbr.fish b/share/functions/abbr.fish
index 4a3c4d2b..e86ea559 100644
--- a/share/functions/abbr.fish
+++ b/share/functions/abbr.fish
@@ -157,18 +157,20 @@ function __fish_abbr_parse_entry -S -a __input __key __value
if test -z "$__value"
set __value __
end
- switch $__input
- case "*=*"
- # No need for bounds-checking because we already matched before
- set -l KV (string split "=" -m 1 -- $__input)
- set $__key $KV[1]
- set $__value $KV[2]
- case "* *"
- set -l KV (string split " " -m 1 -- $__input)
- set $__key $KV[1]
- set $__value $KV[2]
- case "*"
- set $__key $__input
+ # A "=" _before_ any space - we only read the first possible separator
+ # because the key can contain neither spaces nor "="
+ if string match -qr '^[^ ]+=' -- $__input
+ # No need for bounds-checking because we already matched before
+ set -l KV (string split "=" -m 1 -- $__input)
+ set $__key $KV[1]
+ set $__value $KV[2]
+ else if string match -qr '^[^ ]+ .*' -- $__input
+ set -l KV (string split " " -m 1 -- $__input)
+ set $__key $KV[1]
+ set $__value $KV[2]
+ else
+ # This is needed for `erase` et al, where we want to allow passing a value
+ set $__key $__input
end
return 0
end
diff --git a/tests/abbr.in b/tests/abbr.in
index 69fdfb38..be828b08 100644
--- a/tests/abbr.in
+++ b/tests/abbr.in
@@ -31,3 +31,7 @@ abbr -e '~__abbr2'
abbr -- '--__abbr3' 'xyz'
abbr | grep __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"