]> git.corax.cc Git - toolbox/commitdiff
include/in: Fix bug in is_alpha() and is_alnum()
authorMatthias Kruk <m@m10k.eu>
Tue, 20 Apr 2021 13:30:44 +0000 (22:30 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 20 Apr 2021 13:30:44 +0000 (22:30 +0900)
The is_alpha() and is_alnum() functions fail to recognize strings
containing mixed case and digits (in the case of the latter). This
commit fixes the implementations by making perform the check with a
regular expression instead of delegating the work to is_upper(),
is_lower(), and is_digits().

include/is.sh

index d0f804b7be1c99a46b117e6f94031551ef384d05..93846027ed2644c9f507e83df28bf9d52acee65b 100644 (file)
@@ -57,7 +57,7 @@ is_alpha() {
 
        str="$1"
 
-       if is_upper "$str" || is_lower "$str"; then
+       if [[ "$str" =~ ^[a-zA-Z]+$ ]]; then
                return 0
        fi
 
@@ -69,7 +69,7 @@ is_alnum() {
 
        str="$1"
 
-       if is_alpha "$str" || is_digits "$str"; then
+       if [[ "$str" =~ ^[a-zA-Z0-9]+ ]]; then
                return 0
        fi