diff --git a/lib/common/link_helper.dart b/lib/common/link_helper.dart index 5715eb7..24e1e8d 100644 --- a/lib/common/link_helper.dart +++ b/lib/common/link_helper.dart @@ -18,6 +18,40 @@ class LinkHelper { return links.first.text; } + static String removeDuplicateSlashes(String url) { + // Split the URL into components + Uri uri = Uri.parse(url); + + // Get the scheme (e.g., https://) + String scheme = uri.scheme; + + // Get the authority (e.g., www.baidu.com) + String authority = uri.authority; + + // Get the path (e.g., /path/to/resource) + String path = uri.path.replaceAll(RegExp(r'/{2,}'), '/'); + + // Get the query (e.g., ?hello) + String query = uri.query; + + // Get the fragment (e.g., #anchor) + String fragment = uri.fragment; + + // Construct the new URL with no duplicated slashes + String newUrl = '$scheme://$authority$path'; + + // Append the query if it exists + if (query.isNotEmpty) { + newUrl += '?$query'; + } + + // Append the fragment if it exists + if (fragment.isNotEmpty) { + newUrl += '#$fragment'; + } + + return newUrl; + } static getSubscriptionUrl(Radar radar) async { Future _prefs = SharedPreferences.getInstance(); @@ -27,6 +61,7 @@ class LinkHelper { host = prefs.getString("RSSHUB")!; } var url = "$host${radar.path}"; + url = removeDuplicateSlashes(url); if (!radar.isRssHub) { url = radar.path!; }