diff --git a/src/__tests__/lib/exampleData.js b/src/__tests__/lib/exampleData.js index 578ae3cc09b..a400c9c706c 100644 --- a/src/__tests__/lib/exampleData.js +++ b/src/__tests__/lib/exampleData.js @@ -123,7 +123,7 @@ export const makeCrossRealmBot = (args: { name?: string } = {}): CrossRealmBot = is_bot: true, }); -export const realm = 'https://zulip.example.org'; +export const realm = new URL('https://zulip.example.org'); export const zulipVersion = new ZulipVersion('2.1.0-234-g7c3acf4'); @@ -133,7 +133,7 @@ export const makeAccount = ( args: { user?: User, email?: string, - realm?: string, + realm?: URL, apiKey?: string, zulipFeatureLevel?: number | null, zulipVersion?: ZulipVersion | null, @@ -423,7 +423,7 @@ export const action = deepFreeze({ }, login_success: { type: LOGIN_SUCCESS, - realm: selfAccount.realm, + realm: selfAccount.realm.toString(), email: selfAccount.email, apiKey: selfAccount.apiKey, }, @@ -475,7 +475,7 @@ export const action = deepFreeze({ realm_send_welcome_emails: true, realm_show_digest_email: true, realm_signup_notifications_stream_id: 3, - realm_uri: selfAccount.realm, + realm_uri: selfAccount.realm.toString(), realm_video_chat_provider: 1, realm_waiting_period_threshold: 3, zulip_feature_level: 1, diff --git a/src/account-info/AccountDetails.js b/src/account-info/AccountDetails.js index 6bb38e002b5..ae06454b6d6 100644 --- a/src/account-info/AccountDetails.js +++ b/src/account-info/AccountDetails.js @@ -80,6 +80,6 @@ class AccountDetails extends PureComponent { } export default connect((state, props) => ({ - realm: getCurrentRealm(state), + realm: getCurrentRealm(state).toString(), userStatusText: getUserStatusTextForUser(state, props.user.user_id), }))(AccountDetails); diff --git a/src/account/AccountList.js b/src/account/AccountList.js index 7d7f187f795..b3e55426a3e 100644 --- a/src/account/AccountList.js +++ b/src/account/AccountList.js @@ -20,14 +20,14 @@ export default class AccountList extends PureComponent { `${item.email}${item.realm}`} + keyExtractor={item => `${item.email}${item.realm.toString()}`} ItemSeparatorComponent={() => } renderItem={({ item, index }) => ( diff --git a/src/account/AccountPickScreen.js b/src/account/AccountPickScreen.js index 1907de29c04..20a588f090c 100644 --- a/src/account/AccountPickScreen.js +++ b/src/account/AccountPickScreen.js @@ -25,7 +25,7 @@ class AccountPickScreen extends PureComponent { dispatch(switchAccount(index)); }); } else { - dispatch(navigateToRealmScreen(realm)); + dispatch(navigateToRealmScreen(realm.toString())); } }; diff --git a/src/account/__tests__/accountsReducer-test.js b/src/account/__tests__/accountsReducer-test.js index 062d78f3ecc..14782bedc0f 100644 --- a/src/account/__tests__/accountsReducer-test.js +++ b/src/account/__tests__/accountsReducer-test.js @@ -17,8 +17,8 @@ import * as eg from '../../__tests__/lib/exampleData'; describe('accountsReducer', () => { describe('REALM_ADD', () => { describe('on list of identities', () => { - const account1 = eg.makeAccount({ realm: 'https://realm.one.org', apiKey: '' }); - const account2 = eg.makeAccount({ realm: 'https://realm.two.org', apiKey: '' }); + const account1 = eg.makeAccount({ realm: new URL('https://realm.one.org'), apiKey: '' }); + const account2 = eg.makeAccount({ realm: new URL('https://realm.two.org'), apiKey: '' }); const prevState = deepFreeze([account1, account2]); const baseAction = deepFreeze({ type: REALM_ADD, @@ -27,8 +27,8 @@ describe('accountsReducer', () => { }); test('if no account with this realm exists, prepend new one, with empty email/apiKey', () => { - const newRealm = 'https://new.realm.org'; - const action = deepFreeze({ ...baseAction, realm: newRealm }); + const newRealm = new URL('https://new.realm.org'); + const action = deepFreeze({ ...baseAction, realm: newRealm.toString() }); expect(accountsReducer(prevState, action)).toEqual([ eg.makeAccount({ realm: newRealm, email: '', apiKey: '' }), account1, @@ -37,7 +37,7 @@ describe('accountsReducer', () => { }); test('if account with this realm exists, move to front of list', () => { - const action = deepFreeze({ ...baseAction, realm: account2.realm }); + const action = deepFreeze({ ...baseAction, realm: account2.realm.toString() }); expect(accountsReducer(prevState, action)).toEqual([account2, account1]); }); }); @@ -46,7 +46,7 @@ describe('accountsReducer', () => { const existingAccountBase = eg.makeAccount({}); const baseAction = deepFreeze({ type: REALM_ADD, - realm: existingAccountBase.realm, + realm: existingAccountBase.realm.toString(), zulipFeatureLevel: eg.zulipFeatureLevel, zulipVersion: eg.zulipVersion, }); @@ -153,8 +153,8 @@ describe('accountsReducer', () => { }); describe('LOGIN_SUCCESS', () => { - const account1 = eg.makeAccount({ email: '', realm: 'https://one.example.org' }); - const account2 = eg.makeAccount({ realm: 'https://two.example.org' }); + const account1 = eg.makeAccount({ email: '', realm: new URL('https://one.example.org') }); + const account2 = eg.makeAccount({ realm: new URL('https://two.example.org') }); const prevState = deepFreeze([account1, account2]); @@ -168,7 +168,7 @@ describe('accountsReducer', () => { type: LOGIN_SUCCESS, apiKey: newAccount.apiKey, email: newAccount.email, - realm: newAccount.realm, + realm: newAccount.realm.toString(), }); const expectedState = [{ ...newAccount, zulipVersion: account1.zulipVersion }, account2]; @@ -181,7 +181,7 @@ describe('accountsReducer', () => { test('on login, if account does not exist, add as first item', () => { const newAccount = eg.makeAccount({ email: 'newaccount@example.com', - realm: 'https://new.realm.org', + realm: new URL('https://new.realm.org'), zulipVersion: null, zulipFeatureLevel: null, }); @@ -190,7 +190,7 @@ describe('accountsReducer', () => { type: LOGIN_SUCCESS, apiKey: newAccount.apiKey, email: newAccount.email, - realm: newAccount.realm, + realm: newAccount.realm.toString(), }); const expectedState = [newAccount, account1, account2]; @@ -209,7 +209,7 @@ describe('accountsReducer', () => { const action = deepFreeze({ type: LOGIN_SUCCESS, apiKey: newAccount.apiKey, - realm: newAccount.realm, + realm: newAccount.realm.toString(), email: newAccount.email, }); diff --git a/src/account/accountMisc.js b/src/account/accountMisc.js index 5f2252906ff..0a535b9d170 100644 --- a/src/account/accountMisc.js +++ b/src/account/accountMisc.js @@ -8,7 +8,8 @@ export const identityOfAuth: Auth => Identity = identitySlice; export const identityOfAccount: Account => Identity = identitySlice; /** A string corresponding uniquely to an identity, for use in `Map`s. */ -export const keyOfIdentity = ({ realm, email }: Identity): string => `${realm}\0${email}`; +export const keyOfIdentity = ({ realm, email }: Identity): string => + `${realm.toString()}\0${email}`; export const authOfAccount = (account: Account): Auth => { const { realm, email, apiKey } = account; diff --git a/src/account/accountsReducer.js b/src/account/accountsReducer.js index b4cba842e05..102cb769ccd 100644 --- a/src/account/accountsReducer.js +++ b/src/account/accountsReducer.js @@ -16,7 +16,7 @@ import { NULL_ARRAY } from '../nullObjects'; const initialState = NULL_ARRAY; const realmAdd = (state, action) => { - const accountIndex = state.findIndex(account => account.realm === action.realm); + const accountIndex = state.findIndex(account => account.realm.toString() === action.realm); if (accountIndex !== -1) { const newAccount = { @@ -29,7 +29,7 @@ const realmAdd = (state, action) => { return [ { - realm: action.realm, + realm: new URL(action.realm), apiKey: '', email: '', ackedPushToken: null, @@ -60,16 +60,24 @@ const accountSwitch = (state, action) => { const findAccount = (state: AccountsState, identity: Identity): number => { const { realm, email } = identity; return state.findIndex( - account => account.realm === realm && (!account.email || account.email === email), + account => + account.realm.toString() === realm.toString() && (!account.email || account.email === email), ); }; const loginSuccess = (state, action) => { const { realm, email, apiKey } = action; - const accountIndex = findAccount(state, { realm, email }); + const accountIndex = findAccount(state, { realm: new URL(realm), email }); if (accountIndex === -1) { return [ - { realm, email, apiKey, ackedPushToken: null, zulipVersion: null, zulipFeatureLevel: null }, + { + realm: new URL(realm), + email, + apiKey, + ackedPushToken: null, + zulipVersion: null, + zulipFeatureLevel: null, + }, ...state, ]; } diff --git a/src/api/apiFetch.js b/src/api/apiFetch.js index 95e16b02189..a571464b3ed 100644 --- a/src/api/apiFetch.js +++ b/src/api/apiFetch.js @@ -46,7 +46,7 @@ export const apiFetch = async ( auth: Auth, route: string, params: $Diff<$Exact, {| headers: mixed |}>, -) => fetchWithAuth(auth, `${auth.realm}/${apiVersion}/${route}`, params); +) => fetchWithAuth(auth, `${auth.realm.toString()}/${apiVersion}/${route}`, params); export const apiCall = async ( auth: Auth, diff --git a/src/api/settings/getServerSettings.js b/src/api/settings/getServerSettings.js index 4afa0394e63..7f14ca8a6f6 100644 --- a/src/api/settings/getServerSettings.js +++ b/src/api/settings/getServerSettings.js @@ -43,4 +43,4 @@ export type ApiResponseServerSettings = {| /** See https://zulip.com/api/server-settings */ export default async (realm: string): Promise => - apiGet({ apiKey: '', email: '', realm }, 'server_settings'); + apiGet({ apiKey: '', email: '', realm: new URL(realm) }, 'server_settings'); diff --git a/src/api/transportTypes.js b/src/api/transportTypes.js index 25121027c1d..00776b00746 100644 --- a/src/api/transportTypes.js +++ b/src/api/transportTypes.js @@ -16,7 +16,7 @@ * an `Auth`. */ export type Auth = {| - realm: string, + realm: URL, apiKey: string, email: string, |}; diff --git a/src/boot/store.js b/src/boot/store.js index 8eedfc7c138..e3193d753ef 100644 --- a/src/boot/store.js +++ b/src/boot/store.js @@ -156,6 +156,8 @@ const migrations: { [string]: (GlobalState) => GlobalState } = { ...state, accounts: state.accounts.map(a => ({ ...a, + // `a.realm` is a string until migration 15 + // $FlowMigrationFudge realm: a.realm.replace(/\/+$/, ''), })), }), @@ -187,6 +189,16 @@ const migrations: { [string]: (GlobalState) => GlobalState } = { })), }), + // Convert Accounts[].realm from `string` to `URL` + '15': state => ({ + ...state, + accounts: state.accounts.map(a => ({ + ...a, + // $FlowMigrationFudge - `a.realm` will be a string here + realm: new URL(a.realm), + })), + }), + // TIP: When adding a migration, consider just using `dropCache`. }; diff --git a/src/common/OwnAvatar.js b/src/common/OwnAvatar.js index 93c2d472cd2..e3e85d33cbf 100644 --- a/src/common/OwnAvatar.js +++ b/src/common/OwnAvatar.js @@ -28,6 +28,6 @@ class OwnAvatar extends PureComponent { } export default connect(state => ({ - realm: getCurrentRealm(state), + realm: getCurrentRealm(state).toString(), user: getSelfUserDetail(state), }))(OwnAvatar); diff --git a/src/common/UserAvatarWithPresence.js b/src/common/UserAvatarWithPresence.js index 3ce7fa54a1e..c5168511b8d 100644 --- a/src/common/UserAvatarWithPresence.js +++ b/src/common/UserAvatarWithPresence.js @@ -60,5 +60,5 @@ class UserAvatarWithPresence extends PureComponent { } export default connect(state => ({ - realm: getCurrentRealm(state), + realm: getCurrentRealm(state).toString(), }))(UserAvatarWithPresence); diff --git a/src/common/WebLink.js b/src/common/WebLink.js index 957833617e9..98ddc91236d 100644 --- a/src/common/WebLink.js +++ b/src/common/WebLink.js @@ -44,5 +44,5 @@ class WebLink extends PureComponent { } export default connect(state => ({ - realm: getCurrentRealm(state), + realm: getCurrentRealm(state).toString(), }))(WebLink); diff --git a/src/emoji/__tests__/emojiSelectors-test.js b/src/emoji/__tests__/emojiSelectors-test.js index e4ac90cb710..b545860ba5f 100644 --- a/src/emoji/__tests__/emojiSelectors-test.js +++ b/src/emoji/__tests__/emojiSelectors-test.js @@ -11,7 +11,7 @@ describe('getActiveImageEmojiById', () => { const state = { accounts: [ { - realm: 'https://example.com', + realm: new URL('https://example.com'), }, ], realm: { @@ -56,7 +56,7 @@ describe('getActiveImageEmojiById', () => { describe('getAllImageEmojiById', () => { test('get realm emojis with absolute url', () => { const state = { - accounts: [{ realm: 'https://example.com' }], + accounts: [{ realm: new URL('https://example.com') }], realm: { emoji: { 1: { @@ -87,7 +87,7 @@ describe('getAllImageEmojiById', () => { describe('getAllImageEmojiByCode', () => { test('get realm emoji object with emoji names as the keys', () => { const state = { - accounts: [{ realm: 'https://example.com' }], + accounts: [{ realm: new URL('https://example.com') }], realm: { emoji: { 1: { @@ -129,7 +129,7 @@ describe('getAllImageEmojiByCode', () => { describe('getActiveImageEmojiByName', () => { test('get realm emoji object with emoji names as the keys', () => { const state = { - accounts: [{ realm: 'https://example.com' }], + accounts: [{ realm: new URL('https://example.com') }], realm: { emoji: { 1: { diff --git a/src/lightbox/Lightbox.js b/src/lightbox/Lightbox.js index c5d3132ded6..cd86cc397d3 100644 --- a/src/lightbox/Lightbox.js +++ b/src/lightbox/Lightbox.js @@ -115,7 +115,7 @@ class Lightbox extends PureComponent { diff --git a/src/message/fetchActions.js b/src/message/fetchActions.js index 07d2d4c355d..d223222278e 100644 --- a/src/message/fetchActions.js +++ b/src/message/fetchActions.js @@ -311,7 +311,7 @@ export const doInitialFetch = () => async (dispatch: Dispatch, getState: GetStat }, }), ), - tryFetch(() => api.getServerSettings(auth.realm)), + tryFetch(() => api.getServerSettings(auth.realm.toString())), ]); } catch (e) { // This should only happen on a 4xx HTTP status, which should only diff --git a/src/message/messagesActions.js b/src/message/messagesActions.js index 469296bae1f..f90ce348fa7 100644 --- a/src/message/messagesActions.js +++ b/src/message/messagesActions.js @@ -44,11 +44,11 @@ export const messageLinkPress = (href: string) => async ( const auth = getAuth(state); const usersById = getUsersById(state); const streamsById = getStreamsById(state); - const narrow = getNarrowFromLink(href, auth.realm, usersById, streamsById); + const narrow = getNarrowFromLink(href, auth.realm.toString(), usersById, streamsById); if (narrow) { - const anchor = getMessageIdFromLink(href, auth.realm); + const anchor = getMessageIdFromLink(href, auth.realm.toString()); dispatch(doNarrow(narrow, anchor)); - } else if (!isUrlOnRealm(href, auth.realm)) { + } else if (!isUrlOnRealm(href, auth.realm.toString())) { openLink(href); } else { const url = diff --git a/src/nav/__tests__/navReducer-test.js b/src/nav/__tests__/navReducer-test.js index 9aa83f6d44f..add69acfc58 100644 --- a/src/nav/__tests__/navReducer-test.js +++ b/src/nav/__tests__/navReducer-test.js @@ -130,7 +130,7 @@ describe('navReducer', () => { const action = deepFreeze({ type: REHYDRATE, payload: { - accounts: [{ apiKey: '', realm: 'https://example.com' }], + accounts: [{ apiKey: '', realm: new URL('https://example.com') }], users: [], realm: {}, }, @@ -147,8 +147,8 @@ describe('navReducer', () => { type: REHYDRATE, payload: { accounts: [ - { apiKey: '', realm: 'https://example.com', email: 'johndoe@example.com' }, - { apiKey: '', realm: 'https://example.com', email: 'janedoe@example.com' }, + { apiKey: '', realm: new URL('https://example.com'), email: 'johndoe@example.com' }, + { apiKey: '', realm: new URL('https://example.com'), email: 'janedoe@example.com' }, ], users: [], realm: {}, @@ -165,7 +165,9 @@ describe('navReducer', () => { const action = deepFreeze({ type: REHYDRATE, payload: { - accounts: [{ apiKey: '', realm: 'https://example.com', email: 'johndoe@example.com' }], + accounts: [ + { apiKey: '', realm: new URL('https://example.com'), email: 'johndoe@example.com' }, + ], users: [], realm: {}, }, diff --git a/src/notification/index.js b/src/notification/index.js index 3ed221f27b6..eab6e18b538 100644 --- a/src/notification/index.js +++ b/src/notification/index.js @@ -38,7 +38,7 @@ export const getAccountFromNotificationData = ( const urlMatches = []; identities.forEach((account, i) => { - if (account.realm === realm_uri) { + if (account.realm.toString() === realm_uri) { urlMatches.push(i); } }); @@ -49,7 +49,7 @@ export const getAccountFromNotificationData = ( // just a race -- this notification was sent before the logout); or // there's some confusion where the realm_uri we have is different from // the one the server sends in notifications. - const knownUrls = identities.map(({ realm }) => realm); + const knownUrls = identities.map(({ realm }) => realm.toString()); logging.warn('notification realm_uri not found in accounts', { realm_uri, known_urls: knownUrls, diff --git a/src/settings/LegalScreen.js b/src/settings/LegalScreen.js index 5306dc471f1..13689a3eb26 100644 --- a/src/settings/LegalScreen.js +++ b/src/settings/LegalScreen.js @@ -35,5 +35,5 @@ class LegalScreen extends PureComponent { } export default connect(state => ({ - realm: getCurrentRealm(state), + realm: getCurrentRealm(state).toString(), }))(LegalScreen); diff --git a/src/start/AuthScreen.js b/src/start/AuthScreen.js index 3d8c9e9b2a2..63c35412bfe 100644 --- a/src/start/AuthScreen.js +++ b/src/start/AuthScreen.js @@ -226,7 +226,7 @@ class AuthScreen extends PureComponent { const { dispatch, realm } = this.props; const auth = webAuth.authFromCallbackUrl(event.url, otp, realm); if (auth) { - dispatch(loginSuccess(auth.realm, auth.email, auth.apiKey)); + dispatch(loginSuccess(auth.realm.toString(), auth.email, auth.apiKey)); } }; @@ -347,5 +347,5 @@ class AuthScreen extends PureComponent { } export default connect(state => ({ - realm: getCurrentRealm(state), + realm: getCurrentRealm(state).toString(), }))(AuthScreen); diff --git a/src/start/DevAuthScreen.js b/src/start/DevAuthScreen.js index 10259c570a8..3b2cf1fd50d 100644 --- a/src/start/DevAuthScreen.js +++ b/src/start/DevAuthScreen.js @@ -73,7 +73,7 @@ class DevAuthScreen extends PureComponent { try { const { api_key } = await api.devFetchApiKey(partialAuth, email); - this.props.dispatch(loginSuccess(partialAuth.realm, email, api_key)); + this.props.dispatch(loginSuccess(partialAuth.realm.toString(), email, api_key)); this.setState({ progress: false }); } catch (err) { this.setState({ progress: false, error: err.data && err.data.msg }); diff --git a/src/start/PasswordAuthScreen.js b/src/start/PasswordAuthScreen.js index 21a4c7d4b52..6d90687f27d 100644 --- a/src/start/PasswordAuthScreen.js +++ b/src/start/PasswordAuthScreen.js @@ -57,7 +57,7 @@ class PasswordAuthScreen extends PureComponent { try { const fetchedKey = await api.fetchApiKey(partialAuth, email, password); this.setState({ progress: false }); - dispatch(loginSuccess(partialAuth.realm, fetchedKey.email, fetchedKey.api_key)); + dispatch(loginSuccess(partialAuth.realm.toString(), fetchedKey.email, fetchedKey.api_key)); } catch (err) { this.setState({ progress: false, diff --git a/src/start/__tests__/webAuth-test.js b/src/start/__tests__/webAuth-test.js index 4f64b856c88..2c7e654a858 100644 --- a/src/start/__tests__/webAuth-test.js +++ b/src/start/__tests__/webAuth-test.js @@ -3,11 +3,15 @@ import { authFromCallbackUrl } from '../webAuth'; describe('authFromCallbackUrl', () => { const otp = '13579bdf'; - const realm = 'https://chat.example'; + const realm = 'https://chat.example/'; test('success', () => { const url = `zulip://login?realm=${realm}&email=a@b&otp_encrypted_api_key=2636fdeb`; - expect(authFromCallbackUrl(url, otp, realm)).toEqual({ realm, email: 'a@b', apiKey: '5af4' }); + expect(authFromCallbackUrl(url, otp, realm)).toEqual({ + realm: new URL(realm), + email: 'a@b', + apiKey: '5af4', + }); }); test('wrong realm', () => { diff --git a/src/start/webAuth.js b/src/start/webAuth.js index 57bb861f314..568e151e6ac 100644 --- a/src/start/webAuth.js +++ b/src/start/webAuth.js @@ -98,7 +98,7 @@ export const authFromCallbackUrl = ( && otpEncryptedApiKey.length === otp.length ) { const apiKey = extractApiKey(otpEncryptedApiKey, otp); - return { realm, email, apiKey }; + return { realm: new URL(realm), email, apiKey }; } return null; diff --git a/src/utils/__tests__/url-test.js b/src/utils/__tests__/url-test.js index 57a0bed50fb..deac7ba6586 100644 --- a/src/utils/__tests__/url-test.js +++ b/src/utils/__tests__/url-test.js @@ -14,7 +14,7 @@ import type { AutocompletionDefaults } from '../url'; describe('getResource', () => { test('when uri contains domain, do not change, add auth headers', () => { const auth: Auth = { - realm: 'https://example.com/', + realm: new URL('https://example.com/'), apiKey: 'someApiKey', email: 'johndoe@example.com', }; @@ -31,7 +31,7 @@ describe('getResource', () => { }); const exampleAuth: Auth = { - realm: 'https://example.com', + realm: new URL('https://example.com'), email: 'nobody@example.org', apiKey: 'someApiKey', }; diff --git a/src/utils/url.js b/src/utils/url.js index 1266e98b183..dcccf230fb3 100644 --- a/src/utils/url.js +++ b/src/utils/url.js @@ -56,7 +56,9 @@ export const getResource = ( uri: string, auth: Auth, ): {| uri: string, headers?: { [string]: string } |} => - isUrlOnRealm(uri, auth.realm) ? getResourceWithAuth(uri, auth) : getResourceNoAuth(uri); + isUrlOnRealm(uri, auth.realm.toString()) + ? getResourceWithAuth(uri, auth) + : getResourceNoAuth(uri); export type Protocol = 'https://' | 'http://'; diff --git a/src/webview/html/__tests__/render-test.js b/src/webview/html/__tests__/render-test.js index 365af1b6fa9..8f429363c4b 100644 --- a/src/webview/html/__tests__/render-test.js +++ b/src/webview/html/__tests__/render-test.js @@ -11,6 +11,6 @@ describe('typing', () => { email: `${name}@example.com`, }; - expect(messageTypingAsHtml(eg.realm, [user])).not.toContain('&<'); + expect(messageTypingAsHtml(eg.realm.toString(), [user])).not.toContain('&<'); }); }); diff --git a/src/webview/html/messageAsHtml.js b/src/webview/html/messageAsHtml.js index 67c4e73c486..8b4b9e45641 100644 --- a/src/webview/html/messageAsHtml.js +++ b/src/webview/html/messageAsHtml.js @@ -118,7 +118,7 @@ $!${divOpenHtml} const { sender_full_name } = message; const sender_id = message.isOutbox ? backgroundData.ownUser.user_id : message.sender_id; - const avatarUrl = getAvatarFromMessage(message, backgroundData.auth.realm); + const avatarUrl = getAvatarFromMessage(message, backgroundData.auth.realm.toString()); const subheaderHtml = template`
diff --git a/src/webview/js/__tests__/rewriteHtml.js b/src/webview/js/__tests__/rewriteHtml.js index 0833a6bb5dc..2f48d81e8e1 100644 --- a/src/webview/js/__tests__/rewriteHtml.js +++ b/src/webview/js/__tests__/rewriteHtml.js @@ -5,7 +5,7 @@ import rewriteHtml from '../rewriteHtml'; import type { Auth } from '../../../types'; describe('rewriteHtml', () => { - const realm = 'https://realm.example.com'; + const realm = new URL('https://realm.example.com'); global.jsdom.reconfigure({ url: 'file:///nowhere_land/index.html' }); const auth: Auth = { @@ -27,7 +27,7 @@ describe('rewriteHtml', () => { const prefixes = { relative: '', 'root-relative': '/', - 'absolute on-realm': realm, + 'absolute on-realm': realm.toString(), 'absolute off-realm': 'https://example.org', }; diff --git a/src/webview/js/generatedEs3.js b/src/webview/js/generatedEs3.js index 3404fec6839..98f7042bf30 100644 --- a/src/webview/js/generatedEs3.js +++ b/src/webview/js/generatedEs3.js @@ -231,7 +231,7 @@ var compiledWebviewJs = (function (exports) { }); var rewriteImageUrls = function rewriteImageUrls(auth, element) { - var realm = new URL(auth.realm); + var realm = auth.realm; var imageTags = [].concat(element instanceof HTMLImageElement ? [element] : [], Array.from(element.getElementsByTagName('img'))); imageTags.forEach(function (img) { var actualSrc = img.getAttribute('src'); @@ -661,7 +661,7 @@ var compiledWebviewJs = (function (exports) { var handleInitialLoad = function handleInitialLoad(platformOS, scrollMessageId, rawAuth) { var auth = _objectSpread2(_objectSpread2({}, rawAuth), {}, { - realm: rawAuth.realm + realm: new URL(rawAuth.realm) }); if (platformOS === 'ios') { diff --git a/src/webview/js/js.js b/src/webview/js/js.js index 124e75fb304..ed8ae5103ff 100644 --- a/src/webview/js/js.js +++ b/src/webview/js/js.js @@ -548,7 +548,7 @@ export const handleInitialLoad = ( // in its stringified form. rawAuth: {| ...$Diff, realm: string |}, ) => { - const auth: Auth = { ...rawAuth, realm: rawAuth.realm }; + const auth: Auth = { ...rawAuth, realm: new URL(rawAuth.realm) }; // Since its version 5.x, the `react-native-webview` library dispatches our // `message` events at `window` on iOS but `document` on Android. if (platformOS === 'ios') { diff --git a/src/webview/js/rewriteHtml.js b/src/webview/js/rewriteHtml.js index ec877e7aa8d..2ea2cc745e0 100644 --- a/src/webview/js/rewriteHtml.js +++ b/src/webview/js/rewriteHtml.js @@ -16,7 +16,7 @@ const inlineApiRoutes: RegExp[] = ['^/user_uploads/', '^/thumbnail$', '^/avatar/ * inject an API key into its query parameters. */ const rewriteImageUrls = (auth: Auth, element: Element | Document) => { - const realm = new URL(auth.realm); + const realm = auth.realm; // Find the image elements to act on. const imageTags: $ReadOnlyArray = [].concat( diff --git a/src/webview/webViewHandleUpdates.js b/src/webview/webViewHandleUpdates.js index 05a3e359d4c..eb7a07ec9a9 100644 --- a/src/webview/webViewHandleUpdates.js +++ b/src/webview/webViewHandleUpdates.js @@ -73,7 +73,7 @@ const updateTyping = (prevProps: Props, nextProps: Props): WebViewUpdateEventTyp type: 'typing', content: nextProps.typingUsers.length > 0 - ? messageTypingAsHtml(nextProps.backgroundData.auth.realm, nextProps.typingUsers) + ? messageTypingAsHtml(nextProps.backgroundData.auth.realm.toString(), nextProps.typingUsers) : '', });