feat(reddit): add sanitize-sharing-links patch (#407)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
KAZI MMT 2023-05-21 21:54:54 +06:00 committed by GitHub
parent d9a75ea46a
commit 191cc711de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,25 @@
package app.revanced.reddit.patches;
import app.revanced.integrations.utils.LogHelper;
import java.net.MalformedURLException;
import java.net.URL;
public final class SanitizeUrlQueryPatch {
/**
* Strip query parameters from a given URL string.
*
* @param urlString URL string to strip query parameters from.
* @return URL string without query parameters if possible, otherwise the original string.
*/
public static String stripQueryParameters(final String urlString) {
try {
final var url = new URL(urlString);
return url.getProtocol() + "://" + url.getHost() + url.getPath();
} catch (MalformedURLException e) {
LogHelper.printException(() -> "Can not parse URL", e);
return urlString;
}
}
}