From 6bc93f7b7d4e1188b79c5b77d3142f125c93cb27 Mon Sep 17 00:00:00 2001 From: Fabian Freund Date: Wed, 30 Jul 2025 22:04:22 +0200 Subject: [PATCH] refactor uri scheme validation --- app/lib/extensions/uri.dart | 5 +++++ app/lib/utils/uri_parser.dart | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/lib/extensions/uri.dart b/app/lib/extensions/uri.dart index e9a36938..f1d2700f 100644 --- a/app/lib/extensions/uri.dart +++ b/app/lib/extensions/uri.dart @@ -17,6 +17,11 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ + +const _supportedSchemes = {'https', 'http', 'ftp', 'file', 'content', 'about'}; + extension UriX on Uri { Uri get base => Uri.parse('$scheme://$authority'); + + bool get hasSupportedScheme => _supportedSchemes.contains(scheme); } diff --git a/app/lib/utils/uri_parser.dart b/app/lib/utils/uri_parser.dart index 0f571589..fda07830 100644 --- a/app/lib/utils/uri_parser.dart +++ b/app/lib/utils/uri_parser.dart @@ -18,9 +18,9 @@ * along with this program. If not, see . */ import 'package:universal_io/io.dart'; +import 'package:weblibre/extensions/uri.dart'; final _domainRegex = RegExp(r'\.[a-zA-Z]{2,}$'); -const _supportedSchemes = {'https', 'http', 'ftp', 'file', 'content', 'about'}; Uri? tryParseUrl(String? input, {bool eagerParsing = false}) { if (input != null) { @@ -42,7 +42,7 @@ Uri? tryParseUrl(String? input, {bool eagerParsing = false}) { } if (uri.authority.isNotEmpty) { - if (_supportedSchemes.contains(uri.scheme) || !uri.hasScheme) { + if (uri.hasSupportedScheme || !uri.hasScheme) { return uri; } }