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

Side by Side Diff: src/org/adblockplus/sbrowser/contentblocker/engine/Subscriptions.java

Issue 29370856: Issue 4772 - Add temporary fix for removing unsupported filters (Closed)
Patch Set: Changing regex from array to String Created Jan. 30, 2017, 9:42 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Filters that begin with '|$' , '||$' , '@@|$' or '@@||$'
Felix Dahlke 2017/02/07 15:34:15 Nit: Maybe reference the issue? e.g.: // Filters
45 private static final String UNSUPPORTED_FILTERS_REGEX = "^(\\|\\$|\\|\\|\\$|@ @\\|\\$|@@\\|\\|\\$).*";
44 private final HashMap<String, Subscription> subscriptions = new HashMap<String , Subscription>(); 46 private final HashMap<String, Subscription> subscriptions = new HashMap<String , Subscription>();
45 47
46 private final Engine engine; 48 private final Engine engine;
47 private final File subscriptionFolder; 49 private final File subscriptionFolder;
48 private final File cacheFolder; 50 private final File cacheFolder;
49 private final boolean wasUnitialized; 51 private final boolean wasUnitialized;
50 52
51 private Subscriptions(final Engine engine, final File appFolder, final File ca cheFolder) 53 private Subscriptions(final Engine engine, final File appFolder, final File ca cheFolder)
52 { 54 {
53 this.engine = engine; 55 this.engine = engine;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 181 }
180 182
181 final BufferedWriter w = new BufferedWriter( 183 final BufferedWriter w = new BufferedWriter(
182 new OutputStreamWriter(new FileOutputStream(output), "UTF-8")); 184 new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
183 try 185 try
184 { 186 {
185 Log.d(TAG, "Writing " + filters.size() + " filters"); 187 Log.d(TAG, "Writing " + filters.size() + " filters");
186 Engine.writeFilterHeaders(w); 188 Engine.writeFilterHeaders(w);
187 for (final String filter : filters) 189 for (final String filter : filters)
188 { 190 {
189 w.write(filter); 191 // This is a temporary fix to not write filters that might crash Samsung Internet
190 w.write('\n'); 192 // See https://issues.adblockplus.org/ticket/4772
193 if (isFilterSupported(filter))
194 {
195 w.write(filter);
196 w.write('\n');
197 }
198 else
199 {
200 Log.d(TAG, "Ignoring unsupported filter: " + filter);
201 }
191 } 202 }
192 } 203 }
193 finally 204 finally
194 { 205 {
195 w.close(); 206 w.close();
196 } 207 }
197 } 208 }
198 209
210 private static boolean isFilterSupported(String filter)
211 {
212 if (filter.matches(UNSUPPORTED_FILTERS_REGEX))
Felix Dahlke 2017/02/07 15:34:15 Seems we can simplify the function to: return !fi
213 {
214 return false;
215 }
216 return true;
217 }
218
199 public Subscription add(final Subscription sub) 219 public Subscription add(final Subscription sub)
200 { 220 {
201 final String id = sub.getId(); 221 final String id = sub.getId();
202 if (!this.subscriptions.containsKey(id)) 222 if (!this.subscriptions.containsKey(id))
203 { 223 {
204 this.subscriptions.put(id, sub); 224 this.subscriptions.put(id, sub);
205 return sub; 225 return sub;
206 } 226 }
207 return this.subscriptions.get(id); 227 return this.subscriptions.get(id);
208 } 228 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 if (sub != null) 289 if (sub != null)
270 { 290 {
271 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), 291 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub),
272 this.getFiltersFile(sub))) 292 this.getFiltersFile(sub)))
273 { 293 {
274 this.engine.requestUpdateBroadcast(); 294 this.engine.requestUpdateBroadcast();
275 } 295 }
276 } 296 }
277 } 297 }
278 } 298 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld