Skip to content

Commit 613d3c9

Browse files
notif: Show a dialog if received malformed Android Notification URL
1 parent f9cd2f2 commit 613d3c9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/notifications/open.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,29 @@ class NotificationOpenService {
6262
if (!context.mounted) return; // TODO(linter): this is impossible as there's no actual async gap, but the use_build_context_synchronously lint doesn't see that
6363

6464
assert(url.scheme == 'zulip' && url.host == 'notification');
65-
final data = NotificationOpenPayload.parseAndroidNotificationUrl(url);
65+
final data = tryParseAndroidNotificationUrl(context: context, url: url);
66+
if (data == null) return; // TODO(log)
6667
final route = routeForNotification(context: context, data: data);
6768
if (route == null) return; // TODO(log)
6869

6970
// TODO(nav): Better interact with existing nav stack on notif open
7071
unawaited(navigator.push(route));
7172
}
73+
74+
static NotificationOpenPayload? tryParseAndroidNotificationUrl({
75+
required BuildContext context,
76+
required Uri url,
77+
}) {
78+
try {
79+
return NotificationOpenPayload.parseAndroidNotificationUrl(url);
80+
} on FormatException catch (e, st) {
81+
assert(debugLog('$e\n$st'));
82+
final zulipLocalizations = ZulipLocalizations.of(context);
83+
showErrorDialog(context: context,
84+
title: zulipLocalizations.errorNotificationOpenTitle);
85+
return null;
86+
}
87+
}
7288
}
7389

7490
/// The data from a notification that describes what to do

lib/widgets/app.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ class _ZulipAppState extends State<ZulipApp> with WidgetsBindingObserver {
175175
final initialRouteUrl = Uri.tryParse(initialRoute);
176176
if (initialRouteUrl case Uri(scheme: 'zulip', host: 'notification')) {
177177
assert(debugLog('got notif: url: $initialRouteUrl'));
178-
final data =
179-
NotificationOpenPayload.parseAndroidNotificationUrl(initialRouteUrl);
178+
final data = NotificationOpenService.tryParseAndroidNotificationUrl(
179+
context: context,
180+
url: initialRouteUrl);
181+
if (data == null) return null; // TODO(log)
180182
return NotificationOpenService.routeForNotification(
181183
context: context,
182184
data: data);

0 commit comments

Comments
 (0)