Skip to content

Commit 57eea75

Browse files
notif: Show a dialog if received malformed Android Notification URL
1 parent 4b1cc34 commit 57eea75

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
@@ -60,13 +60,29 @@ class NotificationOpenService {
6060
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
6161

6262
assert(url.scheme == 'zulip' && url.host == 'notification');
63-
final data = NotificationOpenPayload.parseAndroidNotificationUrl(url);
63+
final data = tryParseAndroidNotificationUrl(context: context, url: url);
64+
if (data == null) return; // TODO(log)
6465
final route = routeForNotification(context: context, data: data);
6566
if (route == null) return; // TODO(log)
6667

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

7288
/// 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)