From b8bb8d1f4bd1ff3719a9ea54e9a159c3833de2bc Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Thu, 29 Sep 2022 10:15:57 -0400 Subject: [PATCH] Bugfix for F-Droid URL parsing --- lib/app_sources/fdroid.dart | 10 ++++++++-- lib/pages/add_app.dart | 2 +- lib/providers/source_provider.dart | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/app_sources/fdroid.dart b/lib/app_sources/fdroid.dart index 920d67c..4cf5a8f 100644 --- a/lib/app_sources/fdroid.dart +++ b/lib/app_sources/fdroid.dart @@ -9,8 +9,14 @@ class FDroid implements AppSource { @override String standardizeURL(String url) { - RegExp standardUrlRegEx = RegExp('^https?://$host/[^/]+/packages/[^/]+'); - RegExpMatch? match = standardUrlRegEx.firstMatch(url.toLowerCase()); + RegExp standardUrlRegExB = + RegExp('^https?://$host/+[^/]+/+packages/+[^/]+'); + RegExpMatch? match = standardUrlRegExB.firstMatch(url.toLowerCase()); + if (match != null) { + url = 'https://$host/packages/${Uri.parse(url).pathSegments.last}'; + } + RegExp standardUrlRegExA = RegExp('^https?://$host/+packages/+[^/]+'); + match = standardUrlRegExA.firstMatch(url.toLowerCase()); if (match == null) { throw notValidURL(runtimeType.toString()); } diff --git a/lib/pages/add_app.dart b/lib/pages/add_app.dart index 173eab4..673417e 100644 --- a/lib/pages/add_app.dart +++ b/lib/pages/add_app.dart @@ -52,7 +52,7 @@ class _AddAppPageState extends State { sourceProvider .getSource(value ?? '') .standardizeURL( - makeUrlHttps( + preStandardizeUrl( value ?? '')); } catch (e) { return e is String diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index 6cb34fc..4251bdb 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -96,7 +96,7 @@ escapeRegEx(String s) { }); } -makeUrlHttps(String url) { +preStandardizeUrl(String url) { if (url.toLowerCase().indexOf('http://') != 0 && url.toLowerCase().indexOf('https://') != 0) { url = 'https://$url'; @@ -159,7 +159,7 @@ class SourceProvider { List massSources = [GitHubStars()]; AppSource getSource(String url) { - url = makeUrlHttps(url); + url = preStandardizeUrl(url); AppSource? source; for (var s in sources) { if (url.toLowerCase().contains('://${s.host}')) { @@ -186,7 +186,7 @@ class SourceProvider { Future getApp(AppSource source, String url, List additionalData, {String customName = ''}) async { - String standardUrl = source.standardizeURL(makeUrlHttps(url)); + String standardUrl = source.standardizeURL(preStandardizeUrl(url)); AppNames names = source.getAppNames(standardUrl); APKDetails apk = await source.getLatestAPKDetails(standardUrl, additionalData);