Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/sbrowser/contentblocker/engine/Subscriptions.java

Issue 29370856: Issue 4772 - Add temporary fix for removing unsupported filters (Closed)
Left Patch Set: Changing method isFilterUnsupported to isFilterSupported for better readability Created Jan. 19, 2017, 1:23 p.m.
Right Patch Set: Referencing issue and inlining filter supported check Created Feb. 9, 2017, 9:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 23 matching lines...) Expand all
34 34
35 /** 35 /**
36 * This class holds all listed subscriptions and manages the subscription 36 * This class holds all listed subscriptions and manages the subscription
37 * aggregation cache folder. 37 * aggregation cache folder.
38 */ 38 */
39 final class Subscriptions 39 final class Subscriptions
40 { 40 {
41 private static final String TAG = Subscriptions.class.getSimpleName(); 41 private static final String TAG = Subscriptions.class.getSimpleName();
42 private static final String[] USER_SUBSCRIPTIONS = 42 private static final String[] USER_SUBSCRIPTIONS =
43 { Engine.USER_FILTERS_TITLE, Engine.USER_EXCEPTIONS_TITLE }; 43 { Engine.USER_FILTERS_TITLE, Engine.USER_EXCEPTIONS_TITLE };
44 private static final String[] UNSUPPORTED_FILTERS_REGEX = { 44 // Filters that begin with '|$' , '||$' , '@@|$' or '@@||$' need to be removed
Felix Dahlke 2017/01/30 16:24:47 Why is this an array? Looks like there's just a si
diegocarloslima 2017/01/30 17:12:33 Acknowledged.
45 "^(\\|\\$|\\|\\|\\$|@@\\|\\$|@@\\|\\|\\$).*" // Filters that begin with '| $' , '||$' , '@@|$' or '@@||$' 45 // See https://issues.adblockplus.org/ticket/4772
46 }; 46 private static final String UNSUPPORTED_FILTERS_REGEX = "^(\\|\\$|\\|\\|\\$|@ @\\|\\$|@@\\|\\|\\$).*";
47 private final HashMap<String, Subscription> subscriptions = new HashMap<String , Subscription>(); 47 private final HashMap<String, Subscription> subscriptions = new HashMap<String , Subscription>();
48 48
49 private final Engine engine; 49 private final Engine engine;
50 private final File subscriptionFolder; 50 private final File subscriptionFolder;
51 private final File cacheFolder; 51 private final File cacheFolder;
52 private final boolean wasUnitialized; 52 private final boolean wasUnitialized;
53 53
54 private Subscriptions(final Engine engine, final File appFolder, final File ca cheFolder) 54 private Subscriptions(final Engine engine, final File appFolder, final File ca cheFolder)
55 { 55 {
56 this.engine = engine; 56 this.engine = engine;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 final BufferedWriter w = new BufferedWriter( 184 final BufferedWriter w = new BufferedWriter(
185 new OutputStreamWriter(new FileOutputStream(output), "UTF-8")); 185 new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
186 try 186 try
187 { 187 {
188 Log.d(TAG, "Writing " + filters.size() + " filters"); 188 Log.d(TAG, "Writing " + filters.size() + " filters");
189 Engine.writeFilterHeaders(w); 189 Engine.writeFilterHeaders(w);
190 for (final String filter : filters) 190 for (final String filter : filters)
191 { 191 {
192 // This is a temporary fix to not write filters that might crash Samsung Internet 192 // This is a temporary fix to not write filters that might crash Samsung Internet
193 // See https://issues.adblockplus.org/ticket/4772 193 // See https://issues.adblockplus.org/ticket/4772
194 if (isFilterSupported(filter)) 194 if (!filter.matches(UNSUPPORTED_FILTERS_REGEX))
195 { 195 {
196 w.write(filter); 196 w.write(filter);
197 w.write('\n'); 197 w.write('\n');
198 } 198 }
199 else 199 else
200 { 200 {
201 Log.d(TAG, "Ignoring unsupported filter: " + filter); 201 Log.d(TAG, "Ignoring unsupported filter: " + filter);
202 } 202 }
203 } 203 }
204 } 204 }
205 finally 205 finally
206 { 206 {
207 w.close(); 207 w.close();
208 } 208 }
209 }
210
211 private static boolean isFilterSupported(String filter)
212 {
213 for (final String unsupportedFilterRegex : UNSUPPORTED_FILTERS_REGEX)
214 {
215 if (filter.matches(unsupportedFilterRegex))
216 {
217 return false;
218 }
219 }
220 return true;
221 } 209 }
222 210
223 public Subscription add(final Subscription sub) 211 public Subscription add(final Subscription sub)
224 { 212 {
225 final String id = sub.getId(); 213 final String id = sub.getId();
226 if (!this.subscriptions.containsKey(id)) 214 if (!this.subscriptions.containsKey(id))
227 { 215 {
228 this.subscriptions.put(id, sub); 216 this.subscriptions.put(id, sub);
229 return sub; 217 return sub;
230 } 218 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (sub != null) 281 if (sub != null)
294 { 282 {
295 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), 283 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub),
296 this.getFiltersFile(sub))) 284 this.getFiltersFile(sub)))
297 { 285 {
298 this.engine.requestUpdateBroadcast(); 286 this.engine.requestUpdateBroadcast();
299 } 287 }
300 } 288 }
301 } 289 }
302 } 290 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld