Skip to content

Commit

Permalink
notif: Query account by realm URL origin, not full URL
Browse files Browse the repository at this point in the history
This fixes a potential bug, in case the server returned
`realm_url` contains a trailing `/`.
  • Loading branch information
rajveermalviya committed Feb 7, 2025
1 parent ed357a5 commit 4e505a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/notifications/display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,9 @@ class NotificationDisplayManager {
assert(url.scheme == 'zulip' && url.host == 'notification');
final payload = NotificationOpenPayload.parseUrl(url);

final account = globalStore.accounts.firstWhereOrNull((account) =>
account.realmUrl == payload.realmUrl && account.userId == payload.userId);
final account = globalStore.accounts.firstWhereOrNull(
(account) => account.realmUrl.origin == payload.realmUrl.origin
&& account.userId == payload.userId);
if (account == null) return null;

final route = MessageListPage.buildRoute(
Expand Down
15 changes: 15 additions & 0 deletions test/notifications/display_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,21 @@ void main() {
eg.dmMessage(from: eg.otherUser, to: [eg.selfUser]));
});

testWidgets('account queried by realmUrl origin component', (tester) async {
addTearDown(testBinding.reset);
await testBinding.globalStore.add(
eg.selfAccount.copyWith(realmUrl: Uri.parse('http://chat.example')),
eg.initialSnapshot());
await prepare(tester);

await checkOpenNotification(tester,
eg.selfAccount.copyWith(realmUrl: Uri.parse('http://chat.example/')),
eg.streamMessage());
await checkOpenNotification(tester,
eg.selfAccount.copyWith(realmUrl: Uri.parse('http://chat.example')),
eg.streamMessage());
});

testWidgets('no accounts', (tester) async {
await prepare(tester, withAccount: false);
await openNotification(tester, eg.selfAccount, eg.streamMessage());
Expand Down

0 comments on commit 4e505a7

Please sign in to comment.