Avoid PeerTube accepting non-URLs

This commit is contained in:
petlyh 2023-12-26 23:24:30 +01:00 committed by TobiGr
parent 1e93b1dc20
commit 2b2c1546d1
5 changed files with 36 additions and 8 deletions

View File

@ -5,6 +5,8 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Parser;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
public final class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
@ -51,8 +53,13 @@ public final class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFact
@Override
public boolean onAcceptUrl(final String url) {
return url.contains("/accounts/") || url.contains("/a/")
|| url.contains("/video-channels/") || url.contains("/c/");
try {
new URL(url);
return url.contains("/accounts/") || url.contains("/a/")
|| url.contains("/video-channels/") || url.contains("/c/");
} catch (final MalformedURLException e) {
return false;
}
}
/**

View File

@ -5,6 +5,8 @@ import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
public final class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
@ -27,7 +29,12 @@ public final class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFac
@Override
public boolean onAcceptUrl(final String url) throws FoundAdException {
return url.contains("/videos/") || url.contains("/w/");
try {
new URL(url);
return url.contains("/videos/") || url.contains("/w/");
} catch (final MalformedURLException e) {
return false;
}
}
@Override

View File

@ -6,6 +6,8 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Parser;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
public final class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
@ -52,9 +54,10 @@ public final class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFac
@Override
public boolean onAcceptUrl(final String url) {
try {
new URL(url);
getId(url);
return true;
} catch (final ParsingException e) {
} catch (final ParsingException | MalformedURLException e) {
return false;
}
}

View File

@ -6,6 +6,9 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Parser;
import java.net.MalformedURLException;
import java.net.URL;
public final class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
private static final PeertubeStreamLinkHandlerFactory INSTANCE
@ -47,9 +50,10 @@ public final class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
return false;
}
try {
new URL(url);
getId(url);
return true;
} catch (final ParsingException e) {
} catch (final ParsingException | MalformedURLException e) {
return false;
}
}

View File

@ -4,6 +4,8 @@ import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
@ -69,8 +71,13 @@ public final class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFac
@Override
public boolean onAcceptUrl(final String url) {
return url.contains("/videos?") || url.contains("/videos/trending")
|| url.contains("/videos/most-liked") || url.contains("/videos/recently-added")
|| url.contains("/videos/local");
try {
new URL(url);
return url.contains("/videos?") || url.contains("/videos/trending")
|| url.contains("/videos/most-liked") || url.contains("/videos/recently-added")
|| url.contains("/videos/local");
} catch (final MalformedURLException e) {
return false;
}
}
}