| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 = { | 44 // Filters that begin with '|$' , '||$' , '@@|$' or '@@||$' need to be removed |
| 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 Loading... | |
| 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 (!isFilterUnsupported(filter)) | 194 if (!filter.matches(UNSUPPORTED_FILTERS_REGEX)) |
|
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 { | 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 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 } | 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 Loading... | |
| 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 } |
| LEFT | RIGHT |