Filter ABP CSS selectors (#5247)

This commit is contained in:
yubiuser 2023-05-04 12:01:20 +02:00 committed by GitHub
commit cd638b102f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -762,25 +762,21 @@ gravity_ParseFileIntoDomains() {
tr '[:upper:]' '[:lower:]' < "${src}" > "${destination}" tr '[:upper:]' '[:lower:]' < "${src}" > "${destination}"
# 2) Remove carriage returns # 2) Remove carriage returns
sed -i 's/\r$//' "${destination}" # 3) Remove lines starting with ! (ABP Comments)
# 4) Remove lines starting with [ (ABP Header)
# 5) Remove lines containing ABP extended CSS selectors ("##", "#!#", "#@#", "#?#") preceded by a letter
# 6) Remove comments (text starting with "#", include possible spaces before the hash sign)
# 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses)
# 8) Remove empty lines
# 3a) Remove comments (text starting with "#", include possible spaces before the hash sign) sed -i -r \
sed -i 's/\s*#.*//g' "${destination}" -e 's/\r$//' \
-e 's/\s*!.*//g' \
# 3b) Remove lines starting with ! (ABP Comments) -e 's/\s*\[.*//g' \
sed -i 's/\s*!.*//g' "${destination}" -e '/[a-z]\#[$?@]{0,1}\#/d' \
-e 's/\s*#.*//g' \
# 3c) Remove lines starting with [ (ABP Header) -e 's/^.*\s+//g' \
sed -i 's/\s*\[.*//g' "${destination}" -e '/^$/d' "${destination}"
# 4) Remove lines containing "/"
sed -i -r '/(\/).*$/d' "${destination}"
# 5) Remove leading tabs, spaces, etc. (Also removes leading IP addresses)
sed -i -r 's/^.*\s+//g' "${destination}"
# 6) Remove empty lines
sed -i '/^$/d' "${destination}"
chmod 644 "${destination}" chmod 644 "${destination}"
} }