diff --git a/lib/thunder/cubits/deep_links_cubit/deep_links_cubit.dart b/lib/thunder/cubits/deep_links_cubit/deep_links_cubit.dart index dfca168b7..c13d63896 100644 --- a/lib/thunder/cubits/deep_links_cubit/deep_links_cubit.dart +++ b/lib/thunder/cubits/deep_links_cubit/deep_links_cubit.dart @@ -37,7 +37,7 @@ class DeepLinksCubit extends Cubit { link: link, linkType: LinkType.comment, )); - } else if (!link.replaceAll(RegExp(r'https?:\/\/'), '').contains('/')) { + } else if (Uri.tryParse(link)?.pathSegments.isEmpty == true) { emit(state.copyWith( deepLinkStatus: DeepLinkStatus.success, link: link, diff --git a/lib/thunder/pages/thunder_page.dart b/lib/thunder/pages/thunder_page.dart index 5a64b2529..0710190c1 100644 --- a/lib/thunder/pages/thunder_page.dart +++ b/lib/thunder/pages/thunder_page.dart @@ -214,7 +214,7 @@ class _ThunderState extends State { Future _navigateToInstance(String link) async { try { - await navigateToInstancePage(context, instanceHost: link.replaceAll(RegExp(r'https?:\/\/'), '')); + await navigateToInstancePage(context, instanceHost: link.replaceAll(RegExp(r'https?:\/\/'), '').replaceAll('/', '')); } catch (e) { if (context.mounted) { _showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link); @@ -240,12 +240,12 @@ class _ThunderState extends State { } catch (e) { // Ignore exception, if it's not a valid comment, we'll perform the next fallback } + } - // postId not found or could not resolve link. - // show a snackbar with option to open link - if (context.mounted) { - _showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link); - } + // postId not found or could not resolve link. + // show a snackbar with option to open link + if (context.mounted) { + _showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link); } } @@ -267,12 +267,12 @@ class _ThunderState extends State { } catch (e) { // Ignore exception, if it's not a valid comment, we'll perform the next fallback } + } - // commentId not found or could not resolve link. - // show a snackbar with option to open link - if (context.mounted) { - _showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link); - } + // commentId not found or could not resolve link. + // show a snackbar with option to open link + if (context.mounted) { + _showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link); } } @@ -337,7 +337,11 @@ class _ThunderState extends State { showSnackbar(context, state.error ?? l10n.exceptionProcessingUri); case DeepLinkStatus.success: - _handleDeepLinkNavigation(context, linkType: state.linkType, link: state.link); + try { + _handleDeepLinkNavigation(context, linkType: state.linkType, link: state.link); + } catch (e) { + _showLinkProcessingError(context, AppLocalizations.of(context)!.uriNotSupported, state.link!); + } case DeepLinkStatus.unknown: showSnackbar(context, state.error ?? l10n.uriNotSupported);