From 3605ea5c2ad130491947952495cc3a94cf98dab6 Mon Sep 17 00:00:00 2001 From: KAZI MMT <82371061+kazimmt@users.noreply.github.com> Date: Sun, 21 May 2023 21:54:54 +0600 Subject: [PATCH] feat(reddit): add `sanitize-sharing-links` patch (#407) Co-authored-by: oSumAtrIX --- .../reddit/patches/SanitizeUrlQueryPatch.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 integrations/java/app/revanced/reddit/patches/SanitizeUrlQueryPatch.java diff --git a/integrations/java/app/revanced/reddit/patches/SanitizeUrlQueryPatch.java b/integrations/java/app/revanced/reddit/patches/SanitizeUrlQueryPatch.java new file mode 100644 index 000000000..44de897e9 --- /dev/null +++ b/integrations/java/app/revanced/reddit/patches/SanitizeUrlQueryPatch.java @@ -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; + } + } +}