From 5a8efa23885a6e20d2a866bbdc443cb16dc65bca Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 27 Jan 2024 21:01:44 -0500 Subject: [PATCH] F-Droid: Don't pull changelog text if it isn't a raw file from GitHub/GitLab (#1340) --- lib/app_sources/fdroid.dart | 35 ++++++++++++++++++++++++++--------- lib/pages/apps.dart | 10 ++++++++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/app_sources/fdroid.dart b/lib/app_sources/fdroid.dart index 9129f3c..259f824 100644 --- a/lib/app_sources/fdroid.dart +++ b/lib/app_sources/fdroid.dart @@ -3,6 +3,8 @@ import 'dart:convert'; import 'package:easy_localization/easy_localization.dart'; import 'package:html/parser.dart'; import 'package:http/http.dart'; +import 'package:obtainium/app_sources/github.dart'; +import 'package:obtainium/app_sources/gitlab.dart'; import 'package:obtainium/components/generated_form.dart'; import 'package:obtainium/custom_errors.dart'; import 'package:obtainium/providers/source_provider.dart'; @@ -95,17 +97,32 @@ class FDroid extends AppSource { details.names.author = authorLines.first.split(': ').sublist(1).join(': '); } - var changelogUrls = lines.where((l) => l.startsWith('Changelog: ')); + var changelogUrls = lines + .where((l) => l.startsWith('Changelog: ')) + .map((e) => e.split(' ').sublist(1).join(' ')); if (changelogUrls.isNotEmpty) { details.changeLog = changelogUrls.first; - details.changeLog = (await sourceRequest( - details.changeLog! - .split(': ') - .sublist(1) - .join(': ') - .replaceFirst('/blob/', '/raw/'), - additionalSettings)) - .body; + bool isGitHub = false; + bool isGitLab = false; + try { + GitHub().sourceSpecificStandardizeURL(details.changeLog!); + isGitHub = true; + } catch (e) { + // + } + try { + GitLab().sourceSpecificStandardizeURL(details.changeLog!); + isGitLab = true; + } catch (e) { + // + } + if ((isGitHub || isGitLab) && + (details.changeLog?.indexOf('/blob/') ?? -1) >= 0) { + details.changeLog = (await sourceRequest( + details.changeLog!.replaceFirst('/blob/', '/raw/'), + additionalSettings)) + .body; + } } } catch (e) { // Fail silently diff --git a/lib/pages/apps.dart b/lib/pages/apps.dart index 0472143..f4b6b84 100644 --- a/lib/pages/apps.dart +++ b/lib/pages/apps.dart @@ -358,6 +358,16 @@ class AppsPageState extends State { String? changesUrl = appSource.changeLogPageFromStandardUrl(listedApps[appIndex].app.url); String? changeLog = listedApps[appIndex].app.changeLog; + if (changeLog?.split('\n').length == 1) { + if (RegExp( + '(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?') + .hasMatch(changeLog!)) { + if (changesUrl == null) { + changesUrl = changeLog; + changeLog = null; + } + } + } return (changeLog == null && changesUrl == null) ? null : () {