Skip to content

Commit 856a702

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 c5024b1 commit 856a702

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/notifications/display.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,9 @@ class NotificationDisplayManager {
467467
assert(url.scheme == 'zulip' && url.host == 'notification');
468468
final payload = NotificationOpenPayload.parseUrl(url);
469469

470-
final account = globalStore.accounts.firstWhereOrNull((account) =>
471-
account.realmUrl == payload.realmUrl && account.userId == payload.userId);
470+
final account = globalStore.accounts.firstWhereOrNull(
471+
(account) => account.realmUrl.origin == payload.realmUrl.origin
472+
&& account.userId == payload.userId);
472473
if (account == null) return null;
473474

474475
final route = MessageListPage.buildRoute(

test/notifications/display_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,21 @@ void main() {
10361036
eg.dmMessage(from: eg.otherUser, to: [eg.selfUser]));
10371037
});
10381038

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

0 commit comments

Comments
 (0)