Skip to content

Commit fb1b97f

Browse files
notif: Query account by realm URL origin, not full URL
This fixes a potential bug, in case the server returned `realm_url` contains a trailing `/`.
1 parent 4b2f51e commit fb1b97f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/notifications/display.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,9 @@ class NotificationDisplayManager {
470470
assert(url.scheme == 'zulip' && url.host == 'notification');
471471
final payload = NotificationOpenPayload.parseUrl(url);
472472

473-
final account = globalStore.accounts.firstWhereOrNull((account) =>
474-
account.realmUrl == payload.realmUrl && account.userId == payload.userId);
473+
final account = globalStore.accounts.firstWhereOrNull(
474+
(account) => account.realmUrl.origin == payload.realmUrl.origin
475+
&& account.userId == payload.userId);
475476
if (account == null) { // TODO(log)
476477
final zulipLocalizations = ZulipLocalizations.of(context);
477478
showErrorDialog(context: context,

test/notifications/display_test.dart

+15
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,21 @@ void main() {
10371037
eg.dmMessage(from: eg.otherUser, to: [eg.selfUser]));
10381038
});
10391039

1040+
testWidgets('account queried by realmUrl origin component', (tester) async {
1041+
addTearDown(testBinding.reset);
1042+
await testBinding.globalStore.add(
1043+
eg.selfAccount.copyWith(realmUrl: Uri.parse('http://chat.example')),
1044+
eg.initialSnapshot());
1045+
await prepare(tester);
1046+
1047+
await checkOpenNotification(tester,
1048+
eg.selfAccount.copyWith(realmUrl: Uri.parse('http://chat.example/')),
1049+
eg.streamMessage());
1050+
await checkOpenNotification(tester,
1051+
eg.selfAccount.copyWith(realmUrl: Uri.parse('http://chat.example')),
1052+
eg.streamMessage());
1053+
});
1054+
10401055
testWidgets('no accounts', (tester) async {
10411056
await prepare(tester, withAccount: false);
10421057
await openNotification(tester, eg.selfAccount, eg.streamMessage());

0 commit comments

Comments
 (0)