RegEx matches domain names and IP addresses #2463
Labels
Investigating
Open issue or bug, under investigation
triage: Issue Template Ignored
Missing Issue Template
pi-hole/gravity.sh
Line 288 in ddbdb51
In the
gravity_ParseFileIntoDomains()
function the regular expressionsed -nr -e 's/\.{2,}/./g' -e '/\./p'
matches domain names as well as IP addresses. In case it is intended to match exclusively domain names the regular expression should look likesed -r '/([^\.]+\.)+[^\.]{2,}/!d'
.Proof of concept with the original RegEx:
echo "google.com" | awk -F '#' '{print $1}' | awk -F '/' '{print $1}' | awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' | sed -nr -e 's/\.{2,}/./g' -e '/\./p'
google.com
echo "8.8.8.8" | awk -F '#' '{print $1}' | awk -F '/' '{print $1}' | awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' | sed -nr -e 's/\.{2,}/./g' -e '/\./p'
8.8.8.8
Proof of concept with the proposed RegEx:
echo "8.8.8.8" | tr -d '\r' | tr '[:upper:]' '[:lower:]' | sed -r '/(\/|#).*$/d' | sed -r 's/^.*\s+//g' | sed -r '/([^\.]+\.)+[^\.]{2,}/!d'
echo "google.com" | tr -d '\r' | tr '[:upper:]' '[:lower:]' | sed -r '/(\/|#).*$/d' | sed -r 's/^.*\s+//g' | sed -r '/([^\.]+\.)+[^\.]{2,}/!d'
google.com
The text was updated successfully, but these errors were encountered: