skroll / privoxy-adblock

A bash script for OS X that converts adblock lists to privoxy's format
95 stars 24 forks source link

Syntax Error in Resulting .action #8

Open faxotherapy opened 8 years ago

faxotherapy commented 8 years ago

What I realised is that converting EasyList into Privoxy syntax is not that straightforward. Sure, privoxy-adblock deals correctly with the template format used by Privoxy for custom filters and blocking, but doesn't seem to use the proper syntax for most of the entries found in the resulting .action file.

Also, if my understanding is right, EasyList supposes that Adblock Plus does not make any difference between a domain or path; any string matched will be blocked. On the other hand, Privoxy does make a difference between domain and path.

One notable example: if it’s a path, Adblock Plus doesn’t care whether string matching targets the root folder of the site or any location further down the tree. Privoxy does care.

In Privoxy, if an entry does not start with a slash (/) then the entry is deemed as part of the domain name.

Privoxy doc dealing with the above is found at here.

Based on those considerations, I created an add-on to privoxy-adblock to make the resulting lists perfectly compatible with Privoxy. Because Privoxy has two different syntaxes for domain and path, I built the add-on so it deems a malformed entry as domain or path based on a « no non-sense » approach by simply modifying the syntax, so that the amended entry is understood by Privoxy.

Example:

\.com/ads/
.adserver\.com
&ad_id
\.pop-ads\.
/ads/

will become…

.com/ads/
.adserver.com
/.*&ad_id
/.*\.pop-ads\. 
/(.*/)?ads

The use of /(.*/)? gives a chance for the pattern to be matched further down the path.

The resulting files obtained from the add-on have been successfully integrated in Privoxy and no syntax error was detected, contrary to the situation where the add-on wouldn’t be applied afterwards. Currently the add-on is called from my « master » script, which consist of privoxy-adblock script and the add-on.

Also, I must mentioned that there is a certain number of syntax errors in the generated filters that relate to substitution, but it’s not important for the moment. I was more interesting in path blocking.

There seems to be an excellent alternative to the one you based your script: adblock2privoxy package

I’m active on the forum PrxBx; my member name is Faxopita.

skroll commented 8 years ago

Never dead. Just send your pull requests and I'll check them

faxotherapy commented 8 years ago

I discussed this topic on this site under the name Faxopita and offered a script to rectify privoxy-adblock output.