Merge pull request #87 from psacawa/empty-matching-regex-pr
Fix: Patterns matching the empty string rejected
This commit is contained in:
commit
2bc5fdbbd9
|
@ -1,3 +1,7 @@
|
||||||
|
## 1.1.0 - 06 Mar 2020
|
||||||
|
|
||||||
|
* Extended default SHA pattern to match up to 128 digits ( fixes #73 )
|
||||||
|
|
||||||
## 1.0.1 - 05 Jan 2020
|
## 1.0.1 - 05 Jan 2020
|
||||||
|
|
||||||
* Fix default open command discovery ( fixes #70 )
|
* Fix default open command discovery ( fixes #70 )
|
||||||
|
|
|
@ -128,7 +128,8 @@ set -g @fingers-pattern-1 'yolo'
|
||||||
set -g @fingers-pattern-50 'whatever'
|
set -g @fingers-pattern-50 'whatever'
|
||||||
```
|
```
|
||||||
|
|
||||||
Patterns are case insensitive, and grep's extended syntax ( ERE ) should be used.
|
Patterns are case insensitive, and grep's extended syntax ( ERE ) should be used. Patterns
|
||||||
|
matching the empty string are disallowed.
|
||||||
`man grep` for more info.
|
`man grep` for more info.
|
||||||
|
|
||||||
If the introduced regexp contains an error, an error will be shown when
|
If the introduced regexp contains an error, an error will be shown when
|
||||||
|
|
|
@ -7,9 +7,8 @@ TMUX_PRINTER="$CONF_CURRENT_DIR/../vendor/tmux-printer/tmux-printer"
|
||||||
|
|
||||||
declare -A fingers_defaults
|
declare -A fingers_defaults
|
||||||
|
|
||||||
# TODO empty patterns are invalid
|
|
||||||
function check_pattern() {
|
function check_pattern() {
|
||||||
echo "beep beep" | grep -e "$1" 2> /dev/null
|
echo "beep beep" | grep -E -e "$1" 2> /dev/null
|
||||||
|
|
||||||
if [[ $? == "2" ]]; then
|
if [[ $? == "2" ]]; then
|
||||||
echo 0
|
echo 0
|
||||||
|
@ -18,6 +17,14 @@ function check_pattern() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function check_matches_empty_string() {
|
||||||
|
if grep -E -e "$1" <<< "" >/dev/null; then
|
||||||
|
echo 0
|
||||||
|
else
|
||||||
|
echo 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function envify() {
|
function envify() {
|
||||||
echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g"
|
echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g"
|
||||||
}
|
}
|
||||||
|
@ -109,6 +116,13 @@ for pattern in "${PATTERNS_LIST[@]}" ; do
|
||||||
PATTERNS_LIST[$i]="nope{4000}"
|
PATTERNS_LIST[$i]="nope{4000}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
pattern_matches_empty=$(check_matches_empty_string "$pattern")
|
||||||
|
|
||||||
|
if [[ $pattern_matches_empty == 0 ]]; then
|
||||||
|
display_message "fingers-error: user defined pattern $pattern matched the empty string" 5000
|
||||||
|
PATTERNS_LIST[$i]="nope{4000}"
|
||||||
|
fi
|
||||||
|
|
||||||
i=$((i + 1))
|
i=$((i + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue