From 61ff5b2c761b3c8c511cd2628758dcab626094d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 09:44:31 +0200 Subject: [PATCH 1/5] Unifiy sed commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RD WebDesign Signed-off-by: Christian König --- gravity.sh | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/gravity.sh b/gravity.sh index 34cad67d..6ec53038 100755 --- a/gravity.sh +++ b/gravity.sh @@ -768,25 +768,21 @@ gravity_ParseFileIntoDomains() { tr '[:upper:]' '[:lower:]' < "${src}" > "${destination}" # 2) Remove carriage returns - sed -i 's/\r$//' "${destination}" - - # 3a) Remove comments (text starting with "#", include possible spaces before the hash sign) - sed -i 's/\s*#.*//g' "${destination}" - - # 3b) Remove lines starting with ! (ABP Comments) - sed -i 's/\s*!.*//g' "${destination}" - - # 3c) Remove lines starting with [ (ABP Header) - sed -i 's/\s*\[.*//g' "${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}" + # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) + # 4) Remove lines starting with ! (ABP Comments) + # 5) Remove lines starting with [ (ABP Header) + # 6) Remove lines containing "/" + # 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) + # 8) Remove empty lines + + sed -i -r \ + -e 's/\r$//' \ + -e 's/\s*#.*//g' \ + -e 's/\s*!.*//g' \ + -e 's/\s*\[.*//g' \ + -e '/(\/).*$/d' \ + -e 's/^.*\s+//g' \ + -e '/^$/d' "${destination}" chmod 644 "${destination}" } From cc17fe18a9863d6149957728b5f3f3877cc15ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 10:14:59 +0200 Subject: [PATCH 2/5] Remove lines with ABP extended CSS selector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adam Warner Signed-off-by: Christian König --- gravity.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gravity.sh b/gravity.sh index 6ec53038..6ba27119 100755 --- a/gravity.sh +++ b/gravity.sh @@ -768,18 +768,20 @@ gravity_ParseFileIntoDomains() { tr '[:upper:]' '[:lower:]' < "${src}" > "${destination}" # 2) Remove carriage returns - # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) - # 4) Remove lines starting with ! (ABP Comments) - # 5) Remove lines starting with [ (ABP Header) - # 6) Remove lines containing "/" - # 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) - # 8) Remove empty lines + # 3) Remove lines starting with ! (ABP Comments) + # 4) Remove lines starting with [ (ABP Header) + # 5) Remove lines containing ABP extended CSS selectors ("##", "#!#", "#@#", "#?#") + # 6) Remove comments (text starting with "#", include possible spaces before the hash sign) + # 7) Remove lines containing "/" + # 8) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) + # 9) Remove empty lines sed -i -r \ -e 's/\r$//' \ - -e 's/\s*#.*//g' \ -e 's/\s*!.*//g' \ -e 's/\s*\[.*//g' \ + -e '/\#[!|?|@]{0,1}\#/d' \ + -e 's/\s*#.*//g' \ -e '/(\/).*$/d' \ -e 's/^.*\s+//g' \ -e '/^$/d' "${destination}" From 2a0f72015364979fb1955e02bdb27ed13a62efe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 10:25:25 +0200 Subject: [PATCH 3/5] Don't delete lines containing `/` as they should count as invalid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index 6ba27119..f978cd0a 100755 --- a/gravity.sh +++ b/gravity.sh @@ -772,9 +772,8 @@ gravity_ParseFileIntoDomains() { # 4) Remove lines starting with [ (ABP Header) # 5) Remove lines containing ABP extended CSS selectors ("##", "#!#", "#@#", "#?#") # 6) Remove comments (text starting with "#", include possible spaces before the hash sign) - # 7) Remove lines containing "/" - # 8) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) - # 9) Remove empty lines + # 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) + # 8) Remove empty lines sed -i -r \ -e 's/\r$//' \ @@ -782,7 +781,6 @@ gravity_ParseFileIntoDomains() { -e 's/\s*\[.*//g' \ -e '/\#[!|?|@]{0,1}\#/d' \ -e 's/\s*#.*//g' \ - -e '/(\/).*$/d' \ -e 's/^.*\s+//g' \ -e '/^$/d' "${destination}" From d10d59303e48703cb167164b246b1deead4db984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 21:44:49 +0200 Subject: [PATCH 4/5] There is no ! but an $ rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index f978cd0a..7c40bc0d 100755 --- a/gravity.sh +++ b/gravity.sh @@ -779,7 +779,7 @@ gravity_ParseFileIntoDomains() { -e 's/\r$//' \ -e 's/\s*!.*//g' \ -e 's/\s*\[.*//g' \ - -e '/\#[!|?|@]{0,1}\#/d' \ + -e '/\#[$?@]{0,1}\#/d' \ -e 's/\s*#.*//g' \ -e 's/^.*\s+//g' \ -e '/^$/d' "${destination}" From dd3a7a4edb20edef094bc64e7348cfe769382140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 8 Apr 2023 08:01:46 +0200 Subject: [PATCH 5/5] Only delete lines containing separator when preceded by a letter to reduce false positiv (deleting valid comments) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7c40bc0d..925f4724 100755 --- a/gravity.sh +++ b/gravity.sh @@ -770,7 +770,7 @@ gravity_ParseFileIntoDomains() { # 2) Remove carriage returns # 3) Remove lines starting with ! (ABP Comments) # 4) Remove lines starting with [ (ABP Header) - # 5) Remove lines containing ABP extended CSS selectors ("##", "#!#", "#@#", "#?#") + # 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 @@ -779,7 +779,7 @@ gravity_ParseFileIntoDomains() { -e 's/\r$//' \ -e 's/\s*!.*//g' \ -e 's/\s*\[.*//g' \ - -e '/\#[$?@]{0,1}\#/d' \ + -e '/[a-z]\#[$?@]{0,1}\#/d' \ -e 's/\s*#.*//g' \ -e 's/^.*\s+//g' \ -e '/^$/d' "${destination}"