mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 23:08:07 +00:00
Merge pull request #1178 from pi-hole/fix/validation
Use perl instead of grep for domain validation
This commit is contained in:
commit
0375a3caa3
@ -58,7 +58,7 @@ EscapeRegexp() {
|
|||||||
# This way we may safely insert an arbitrary
|
# This way we may safely insert an arbitrary
|
||||||
# string in our regular expressions
|
# string in our regular expressions
|
||||||
# Also remove leading "." if present
|
# Also remove leading "." if present
|
||||||
echo $* | sed 's/^\.//' | sed "s/[]\\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g"
|
echo $* | sed 's/^\.*//' | sed "s/[]\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g"
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleOther(){
|
HandleOther(){
|
||||||
@ -66,7 +66,7 @@ HandleOther(){
|
|||||||
domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1")
|
domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1")
|
||||||
|
|
||||||
#check validity of domain
|
#check validity of domain
|
||||||
validDomain=$(echo "${domain}" | grep -P '^(?!.*[^a-z0-9-\.].*)\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b')
|
validDomain=$(echo "${domain}" | perl -lne 'print if /^(?!.*[^a-z0-9-\.].*)\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)*[a-z]{2,63}\b/')
|
||||||
if [ -z "${validDomain}" ]; then
|
if [ -z "${validDomain}" ]; then
|
||||||
echo "::: $1 is not a valid argument or domain name"
|
echo "::: $1 is not a valid argument or domain name"
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user