mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-13 13:26:43 +02:00
Merge pull request #2273 from wodin/use-built-in-url-resolver
Use built-in method to fix HTML link resolution
This commit is contained in:
@ -9,32 +9,7 @@ import 'package:obtainium/providers/apps_provider.dart';
|
|||||||
import 'package:obtainium/providers/source_provider.dart';
|
import 'package:obtainium/providers/source_provider.dart';
|
||||||
|
|
||||||
String ensureAbsoluteUrl(String ambiguousUrl, Uri referenceAbsoluteUrl) {
|
String ensureAbsoluteUrl(String ambiguousUrl, Uri referenceAbsoluteUrl) {
|
||||||
if (ambiguousUrl.startsWith('//')) {
|
return referenceAbsoluteUrl.resolve(ambiguousUrl).toString();
|
||||||
ambiguousUrl = '${referenceAbsoluteUrl.scheme}:$ambiguousUrl';
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Uri.parse(ambiguousUrl).origin;
|
|
||||||
return ambiguousUrl;
|
|
||||||
} catch (err) {
|
|
||||||
// is relative
|
|
||||||
}
|
|
||||||
var currPathSegments = referenceAbsoluteUrl.path
|
|
||||||
.split('/')
|
|
||||||
.where((element) => element.trim().isNotEmpty)
|
|
||||||
.toList();
|
|
||||||
String absoluteUrl;
|
|
||||||
if (ambiguousUrl.startsWith('/')) {
|
|
||||||
absoluteUrl = '${referenceAbsoluteUrl.origin}$ambiguousUrl';
|
|
||||||
} else if (currPathSegments.isEmpty) {
|
|
||||||
absoluteUrl = '${referenceAbsoluteUrl.origin}/$ambiguousUrl';
|
|
||||||
} else if (ambiguousUrl.split('/').where((e) => e.isNotEmpty).length == 1) {
|
|
||||||
absoluteUrl =
|
|
||||||
'${referenceAbsoluteUrl.origin}/${currPathSegments.join('/')}/$ambiguousUrl';
|
|
||||||
} else {
|
|
||||||
absoluteUrl =
|
|
||||||
'${referenceAbsoluteUrl.origin}/${currPathSegments.sublist(0, currPathSegments.length - (currPathSegments.last.contains('.') ? 1 : 0)).join('/')}/$ambiguousUrl';
|
|
||||||
}
|
|
||||||
return Uri.parse(absoluteUrl).toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int compareAlphaNumeric(String a, String b) {
|
int compareAlphaNumeric(String a, String b) {
|
||||||
|
Reference in New Issue
Block a user