Left: | ||
Right: |
OLD | NEW |
---|---|
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 Loading... | |
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 = { | |
45 "^(\\|\\$|\\|\\|\\$|@@\\|\\$|@@\\|\\|\\$).*" // Filters that begin with '| $' , '||$' , '@@|$' or '@@||$' | |
46 }; | |
44 private final HashMap<String, Subscription> subscriptions = new HashMap<String , Subscription>(); | 47 private final HashMap<String, Subscription> subscriptions = new HashMap<String , Subscription>(); |
45 | 48 |
46 private final Engine engine; | 49 private final Engine engine; |
47 private final File subscriptionFolder; | 50 private final File subscriptionFolder; |
48 private final File cacheFolder; | 51 private final File cacheFolder; |
49 private final boolean wasUnitialized; | 52 private final boolean wasUnitialized; |
50 | 53 |
51 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) |
52 { | 55 { |
53 this.engine = engine; | 56 this.engine = engine; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 } | 182 } |
180 | 183 |
181 final BufferedWriter w = new BufferedWriter( | 184 final BufferedWriter w = new BufferedWriter( |
182 new OutputStreamWriter(new FileOutputStream(output), "UTF-8")); | 185 new OutputStreamWriter(new FileOutputStream(output), "UTF-8")); |
183 try | 186 try |
184 { | 187 { |
185 Log.d(TAG, "Writing " + filters.size() + " filters"); | 188 Log.d(TAG, "Writing " + filters.size() + " filters"); |
186 Engine.writeFilterHeaders(w); | 189 Engine.writeFilterHeaders(w); |
187 for (final String filter : filters) | 190 for (final String filter : filters) |
188 { | 191 { |
189 w.write(filter); | 192 // This is a temporary fix to not write filters that might crash Samsung Internet |
190 w.write('\n'); | 193 // See https://issues.adblockplus.org/ticket/4772 |
194 if (!isFilterUnsupported(filter)) | |
anton
2017/01/09 09:54:43
it would be better to have positive condition inst
diegocarloslima
2017/01/19 13:16:42
Acknowledged.
| |
195 { | |
196 w.write(filter); | |
197 w.write('\n'); | |
198 } | |
199 else | |
200 { | |
201 Log.d(TAG, "Ignoring unsupported filter: " + filter); | |
202 } | |
191 } | 203 } |
192 } | 204 } |
193 finally | 205 finally |
194 { | 206 { |
195 w.close(); | 207 w.close(); |
196 } | 208 } |
197 } | 209 } |
198 | 210 |
211 private static boolean isFilterUnsupported(String filter) | |
212 { | |
213 for (final String unsupportedFilterRegex : UNSUPPORTED_FILTERS_REGEX) | |
214 { | |
215 if (filter.matches(unsupportedFilterRegex)) | |
216 { | |
217 return true; | |
218 } | |
219 } | |
220 return false; | |
221 } | |
222 | |
199 public Subscription add(final Subscription sub) | 223 public Subscription add(final Subscription sub) |
200 { | 224 { |
201 final String id = sub.getId(); | 225 final String id = sub.getId(); |
202 if (!this.subscriptions.containsKey(id)) | 226 if (!this.subscriptions.containsKey(id)) |
203 { | 227 { |
204 this.subscriptions.put(id, sub); | 228 this.subscriptions.put(id, sub); |
205 return sub; | 229 return sub; |
206 } | 230 } |
207 return this.subscriptions.get(id); | 231 return this.subscriptions.get(id); |
208 } | 232 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 if (sub != null) | 293 if (sub != null) |
270 { | 294 { |
271 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), | 295 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), |
272 this.getFiltersFile(sub))) | 296 this.getFiltersFile(sub))) |
273 { | 297 { |
274 this.engine.requestUpdateBroadcast(); | 298 this.engine.requestUpdateBroadcast(); |
275 } | 299 } |
276 } | 300 } |
277 } | 301 } |
278 } | 302 } |
OLD | NEW |