From 95947de399ad161ca4f6acec25a7471d4fec2219 Mon Sep 17 00:00:00 2001 From: Ray Kraesig Date: Mon, 28 Oct 2019 17:48:23 -0700 Subject: [PATCH] notifications: normalize case of realm_uri and account.realm The Zulip server's `realm_uri` may not match `account.realm`, for a number of reasons. One of the more banal ones is that Zulip servers generally send `realm_uri` in lowercase, as is customary for hostnames... but users will often type caPITAL LETTERS IN THE REAlm field at initial logon. (This being a mobile app, though, it more often results from autocorrect autocapitalizating than from fumble-fingering Caps Lock.) The proper fix is to compare `realm_uri` with the equivalent token we get from `server_settings` at logon. In the interim, we can stem the flood of unhelpful errors in Sentry somewhat just by making the realm lowercase. --- src/notification/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/notification/index.js b/src/notification/index.js index ad32ce6f38b..88cabb07233 100644 --- a/src/notification/index.js +++ b/src/notification/index.js @@ -59,9 +59,18 @@ export const getAccountFromNotificationData = ( return null; } + // The `realm_uri` we get from the server should be case-normalized already; + // but better safe than sorry. + const normalized_realm_uri = realm_uri.toLowerCase(); const urlMatches = []; identities.forEach((account, i) => { - if (account.realm === realm_uri) { + // `account.realm` is _not_ case-normalized; it's straight from user input, + // which (judging from error reports) autocorrect seems to be forcibly + // autocapitalizing on some devices. + // + // (TODO: instead of performing case-mangling, just compare against the + // value of `realm_uri` we get from `/server_settings` at login time.) + if (account.realm.toLowerCase() === normalized_realm_uri) { urlMatches.push(i); } });