Skip to content

Commit b1d164b

Browse files
author
LisoUseInAIKyrios
committed
fix(YouTube - Litho filter): Correctly filter identifier of older YouTube targets
1 parent 87c39dd commit b1d164b

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/Filter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public enum FilterContentType {
4141
* Adds callbacks to {@link #isFiltered(String, String, byte[], StringFilterGroup, FilterContentType, int)}
4242
* if any of the groups are found.
4343
* <p>
44-
* Note: This callback is done only during the initial component creation,
45-
* and the path will always be an empty string.
4644
*/
4745
protected final void addIdentifierCallbacks(StringFilterGroup... groups) {
4846
identifierCallbacks.addAll(Arrays.asList(groups));

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/LithoFilterPatch.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ private static final class DummyFilter extends Filter { }
127127
private static void filterUsingCallbacks(StringTrieSearch pathSearchTree,
128128
Filter filter, List<StringFilterGroup> groups,
129129
Filter.FilterContentType type) {
130+
String filterSimpleName = filter.getClass().getSimpleName();
131+
130132
for (StringFilterGroup group : groups) {
131133
if (!group.includeInSearch()) {
132134
continue;
133135
}
134136

135137
for (String pattern : group.filters) {
136-
String filterSimpleName = filter.getClass().getSimpleName();
137-
138138
pathSearchTree.addPattern(pattern, (textSearched, matchedStartIndex,
139139
matchedLength, callbackParameter) -> {
140140
if (!group.isEnabled()) return false;
@@ -162,6 +162,7 @@ private static void filterUsingCallbacks(StringTrieSearch pathSearchTree,
162162

163163
/**
164164
* Injection point. Called off the main thread.
165+
* Targets 20.22+
165166
*/
166167
public static void setProtoBuffer(byte[] buffer) {
167168
// Set the buffer to a thread local. The buffer will remain in memory, even after the call to #filter completes.
@@ -194,30 +195,30 @@ public static void setProtoBuffer(@Nullable ByteBuffer buffer) {
194195
*/
195196
public static boolean isFiltered(String lithoIdentifier, StringBuilder pathBuilder) {
196197
try {
198+
if (lithoIdentifier.isEmpty() && pathBuilder.length() == 0) {
199+
return false;
200+
}
201+
197202
byte[] buffer = bufferThreadLocal.get();
198203
// Potentially the buffer may have been null or never set up until now.
199204
// Use an empty buffer so the litho id/path filters still work correctly.
200205
if (buffer == null) {
201206
buffer = EMPTY_BYTE_ARRAY;
202207
}
203208

204-
String path = pathBuilder.toString();
205-
LithoFilterParameters parameter = new LithoFilterParameters(lithoIdentifier, path, buffer);
209+
LithoFilterParameters parameter = new LithoFilterParameters(
210+
lithoIdentifier, pathBuilder.toString(), buffer);
206211
Logger.printDebug(() -> "Searching " + parameter);
207212

208-
if (path.isEmpty()) {
209-
// Identifier is filtered only if there is no path,
210-
// meaning no component or sub components have been created yet.
211-
if (identifierSearchTree.matches(parameter.identifier, parameter)) {
212-
return true;
213-
}
214-
} else {
215-
if (pathSearchTree.matches(parameter.path, parameter)) {
216-
return true;
217-
}
213+
if (identifierSearchTree.matches(parameter.identifier, parameter)) {
214+
return true;
215+
}
216+
217+
if (pathSearchTree.matches(parameter.path, parameter)) {
218+
return true;
218219
}
219220
} catch (Exception ex) {
220-
Logger.printException(() -> "Litho filter failure", ex);
221+
Logger.printException(() -> "isFiltered failure", ex);
221222
}
222223

223224
return false;

0 commit comments

Comments
 (0)