Merge pull request #87 from psacawa/empty-matching-regex-pr

Fix: Patterns matching the empty string rejected
This commit is contained in:
Morantron 2021-11-16 19:40:59 +01:00 committed by GitHub
commit 2bc5fdbbd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View File

@ -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
* Fix default open command discovery ( fixes #70 )

View File

@ -128,7 +128,8 @@ set -g @fingers-pattern-1 'yolo'
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.
If the introduced regexp contains an error, an error will be shown when

View File

@ -7,9 +7,8 @@ TMUX_PRINTER="$CONF_CURRENT_DIR/../vendor/tmux-printer/tmux-printer"
declare -A fingers_defaults
# TODO empty patterns are invalid
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
echo 0
@ -18,6 +17,14 @@ function check_pattern() {
fi
}
function check_matches_empty_string() {
if grep -E -e "$1" <<< "" >/dev/null; then
echo 0
else
echo 1
fi
}
function envify() {
echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g"
}
@ -109,6 +116,13 @@ for pattern in "${PATTERNS_LIST[@]}" ; do
PATTERNS_LIST[$i]="nope{4000}"
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))
done