Skip to content

Commit ad41bcc

Browse files
committed
Remove support for adblock style lists to prevent false positives
Signed-off-by: Adam Warner <[email protected]>
1 parent e7af42a commit ad41bcc

File tree

1 file changed

+1
-40
lines changed

1 file changed

+1
-40
lines changed

gravity.sh

+1-40
Original file line numberDiff line numberDiff line change
@@ -353,46 +353,7 @@ gravity_ParseFileIntoDomains() {
353353
# Determine how to parse individual source file formats
354354
if [[ "${firstLine,,}" =~ (adblock|ublock|^!) ]]; then
355355
# Compare $firstLine against lower case words found in Adblock lists
356-
echo -ne " ${INFO} Format: Adblock"
357-
358-
# Define symbols used as comments: [!
359-
# "||.*^" includes the "Example 2" domains we can extract
360-
# https://adblockplus.org/filter-cheatsheet
361-
abpFilter="/^(\\[|!)|^(\\|\\|.*\\^)/"
362-
363-
# Parse Adblock lists by extracting "Example 2" domains
364-
# Logic: Ignore lines which do not include comments or domain name anchor
365-
awk ''"${abpFilter}"' {
366-
# Remove valid adblock type options
367-
gsub(/\$?~?(important|third-party|popup|subdocument|websocket),?/, "", $0)
368-
# Remove starting domain name anchor "||" and ending seperator "^"
369-
gsub(/^(\|\|)|(\^)/, "", $0)
370-
# Remove invalid characters (*/,=$)
371-
if($0 ~ /[*\/,=\$]/) { $0="" }
372-
# Remove lines which are only IPv4 addresses
373-
if($0 ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) { $0="" }
374-
if($0) { print $0 }
375-
}' "${source}" > "${destination}"
376-
377-
# Determine if there are Adblock exception rules
378-
# https://adblockplus.org/filters
379-
if grep -q "^@@||" "${source}" &> /dev/null; then
380-
# Parse Adblock lists by extracting exception rules
381-
# Logic: Ignore lines which do not include exception format "@@||example.com^"
382-
awk -F "[|^]" '/^@@\|\|.*\^/ {
383-
# Remove valid adblock type options
384-
gsub(/\$?~?(third-party)/, "", $0)
385-
# Remove invalid characters (*/,=$)
386-
if($0 ~ /[*\/,=\$]/) { $0="" }
387-
if($3) { print $3 }
388-
}' "${source}" > "${destination}.exceptionsFile.tmp"
389-
390-
# Remove exceptions
391-
comm -23 "${destination}" <(sort "${destination}.exceptionsFile.tmp") > "${source}"
392-
mv "${source}" "${destination}"
393-
fi
394-
395-
echo -e "${OVER} ${TICK} Format: Adblock"
356+
echo -ne " ${CROSS} Format: Adblock (list type not supported)"
396357
elif grep -q "^address=/" "${source}" &> /dev/null; then
397358
# Parse Dnsmasq format lists
398359
echo -e " ${CROSS} Format: Dnsmasq (list type not supported)"

0 commit comments

Comments
 (0)