fix(YouTube - Litho filter): Correctly filter identifier of older YouTube targets
This commit is contained in:
parent
87c39dd485
commit
b1d164b446
2 changed files with 16 additions and 17 deletions
|
|
@ -41,8 +41,6 @@ abstract class Filter {
|
||||||
* Adds callbacks to {@link #isFiltered(String, String, byte[], StringFilterGroup, FilterContentType, int)}
|
* Adds callbacks to {@link #isFiltered(String, String, byte[], StringFilterGroup, FilterContentType, int)}
|
||||||
* if any of the groups are found.
|
* if any of the groups are found.
|
||||||
* <p>
|
* <p>
|
||||||
* Note: This callback is done only during the initial component creation,
|
|
||||||
* and the path will always be an empty string.
|
|
||||||
*/
|
*/
|
||||||
protected final void addIdentifierCallbacks(StringFilterGroup... groups) {
|
protected final void addIdentifierCallbacks(StringFilterGroup... groups) {
|
||||||
identifierCallbacks.addAll(Arrays.asList(groups));
|
identifierCallbacks.addAll(Arrays.asList(groups));
|
||||||
|
|
|
||||||
|
|
@ -127,14 +127,14 @@ public final class LithoFilterPatch {
|
||||||
private static void filterUsingCallbacks(StringTrieSearch pathSearchTree,
|
private static void filterUsingCallbacks(StringTrieSearch pathSearchTree,
|
||||||
Filter filter, List<StringFilterGroup> groups,
|
Filter filter, List<StringFilterGroup> groups,
|
||||||
Filter.FilterContentType type) {
|
Filter.FilterContentType type) {
|
||||||
|
String filterSimpleName = filter.getClass().getSimpleName();
|
||||||
|
|
||||||
for (StringFilterGroup group : groups) {
|
for (StringFilterGroup group : groups) {
|
||||||
if (!group.includeInSearch()) {
|
if (!group.includeInSearch()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String pattern : group.filters) {
|
for (String pattern : group.filters) {
|
||||||
String filterSimpleName = filter.getClass().getSimpleName();
|
|
||||||
|
|
||||||
pathSearchTree.addPattern(pattern, (textSearched, matchedStartIndex,
|
pathSearchTree.addPattern(pattern, (textSearched, matchedStartIndex,
|
||||||
matchedLength, callbackParameter) -> {
|
matchedLength, callbackParameter) -> {
|
||||||
if (!group.isEnabled()) return false;
|
if (!group.isEnabled()) return false;
|
||||||
|
|
@ -162,6 +162,7 @@ public final class LithoFilterPatch {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injection point. Called off the main thread.
|
* Injection point. Called off the main thread.
|
||||||
|
* Targets 20.22+
|
||||||
*/
|
*/
|
||||||
public static void setProtoBuffer(byte[] buffer) {
|
public static void setProtoBuffer(byte[] buffer) {
|
||||||
// Set the buffer to a thread local. The buffer will remain in memory, even after the call to #filter completes.
|
// Set the buffer to a thread local. The buffer will remain in memory, even after the call to #filter completes.
|
||||||
|
|
@ -194,6 +195,10 @@ public final class LithoFilterPatch {
|
||||||
*/
|
*/
|
||||||
public static boolean isFiltered(String lithoIdentifier, StringBuilder pathBuilder) {
|
public static boolean isFiltered(String lithoIdentifier, StringBuilder pathBuilder) {
|
||||||
try {
|
try {
|
||||||
|
if (lithoIdentifier.isEmpty() && pathBuilder.length() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
byte[] buffer = bufferThreadLocal.get();
|
byte[] buffer = bufferThreadLocal.get();
|
||||||
// Potentially the buffer may have been null or never set up until now.
|
// Potentially the buffer may have been null or never set up until now.
|
||||||
// Use an empty buffer so the litho id/path filters still work correctly.
|
// Use an empty buffer so the litho id/path filters still work correctly.
|
||||||
|
|
@ -201,23 +206,19 @@ public final class LithoFilterPatch {
|
||||||
buffer = EMPTY_BYTE_ARRAY;
|
buffer = EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = pathBuilder.toString();
|
LithoFilterParameters parameter = new LithoFilterParameters(
|
||||||
LithoFilterParameters parameter = new LithoFilterParameters(lithoIdentifier, path, buffer);
|
lithoIdentifier, pathBuilder.toString(), buffer);
|
||||||
Logger.printDebug(() -> "Searching " + parameter);
|
Logger.printDebug(() -> "Searching " + parameter);
|
||||||
|
|
||||||
if (path.isEmpty()) {
|
if (identifierSearchTree.matches(parameter.identifier, parameter)) {
|
||||||
// Identifier is filtered only if there is no path,
|
return true;
|
||||||
// meaning no component or sub components have been created yet.
|
}
|
||||||
if (identifierSearchTree.matches(parameter.identifier, parameter)) {
|
|
||||||
return true;
|
if (pathSearchTree.matches(parameter.path, parameter)) {
|
||||||
}
|
return true;
|
||||||
} else {
|
|
||||||
if (pathSearchTree.matches(parameter.path, parameter)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.printException(() -> "Litho filter failure", ex);
|
Logger.printException(() -> "isFiltered failure", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue