Skip to content

Commit efe3567

Browse files
committed
openLink: Have link-opening functions take URL objects, not strings
For the following URLs, this adds a round-trip through the URL constructor before passing it along to be opened: - https://zulip.readthedocs.io/en/stable/overview/release-lifecycle.html#compatibility-and-upgrading - https://zulip.readthedocs.io/en/stable/production/mobile-push-notifications.html - https://zulip.com/policies/?nav=no - https://itunes.apple.com/app/zulip/id1203036395 - https://play.google.com/store/apps/details?id=com.zulipmobile - the URL passed to webAuth.openBrowser (which was actually already round-tripped through the URL constructor; see its caller) - A tapped link in a message, when the link is off-realm We expect just the last of these to have a functional change: it'll make #4136 apply more widely ("[iOS] Links get double-%-encoded, breaking downloads"): #5650 (comment) But we'll fix #4136 in the next commit.
1 parent da63e22 commit efe3567

File tree

12 files changed

+27
-24
lines changed

12 files changed

+27
-24
lines changed

src/common/ServerCompatBanner.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ export default function ServerCompatBanner(props: Props): Node {
101101
openLinkWithUserPreference(
102102
// TODO: Instead, link to new Help Center doc once we have it:
103103
// https://github.com/zulip/zulip/issues/23842
104-
'https://zulip.readthedocs.io/en/stable/overview/release-lifecycle.html#compatibility-and-upgrading',
104+
new URL(
105+
'https://zulip.readthedocs.io/en/stable/overview/release-lifecycle.html#compatibility-and-upgrading',
106+
),
105107
settings,
106108
);
107109
},

src/common/ServerPushSetupBanner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default function PushNotifsSetupBanner(props: Props): Node {
8282
label: 'Learn more',
8383
onPress: () => {
8484
openLinkWithUserPreference(
85-
'https://zulip.readthedocs.io/en/stable/production/mobile-push-notifications.html',
85+
new URL('https://zulip.readthedocs.io/en/stable/production/mobile-push-notifications.html'),
8686
settings,
8787
);
8888
},

src/common/WebLink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default function WebLink(props: Props): React.Node {
4747
<ZulipText
4848
style={componentStyles.link}
4949
onPress={() => {
50-
openLinkWithUserPreference(url.toString(), globalSettings);
50+
openLinkWithUserPreference(url, globalSettings);
5151
}}
5252
{...zulipTextProps}
5353
/>

src/lightbox/LightboxActionSheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type ButtonType = {|
3939
const tryToDownloadImage = async ({ src, auth }: DownloadImageType) => {
4040
const tempUrl = await api.tryGetFileTemporaryUrl(src, auth);
4141
if (tempUrl === null) {
42-
openLinkEmbedded(src.toString());
42+
openLinkEmbedded(src);
4343
return;
4444
}
4545

src/lightbox/shareImage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default async (url: URL, auth: Auth) => {
2828
//
2929
// TODO(?): Could find a better way to convey this.
3030
showToast('Please share the image from your browser');
31-
openLinkEmbedded(url.toString());
31+
openLinkEmbedded(url);
3232
return;
3333
}
3434

src/message/messagesActions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ export const messageLinkPress =
248248

249249
await dispatch(doNarrowNearLink(narrow, nearOperand));
250250
} else if (!isUrlOnRealm(parsedUrl, auth.realm)) {
251-
openLinkWithUserPreference(href, getGlobalSettings());
251+
openLinkWithUserPreference(parsedUrl, getGlobalSettings());
252252
} else {
253253
const url = (await api.tryGetFileTemporaryUrl(parsedUrl, auth)) ?? parsedUrl;
254-
openLinkWithUserPreference(url.toString(), getGlobalSettings());
254+
openLinkWithUserPreference(url, getGlobalSettings());
255255
}
256256
};

src/settings/LegalScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export default function LegalScreen(props: Props): Node {
2525
const globalSettings = useGlobalSelector(getGlobalSettings);
2626

2727
const openZulipPolicies = useCallback(() => {
28-
openLinkWithUserPreference('https://zulip.com/policies/?nav=no', globalSettings);
28+
openLinkWithUserPreference(new URL('https://zulip.com/policies/?nav=no'), globalSettings);
2929
}, [globalSettings]);
3030

3131
const openRealmPolicies = useCallback(() => {
32-
openLinkWithUserPreference(new URL('/policies/?nav=no', realm).toString(), globalSettings);
32+
openLinkWithUserPreference(new URL('/policies/?nav=no', realm), globalSettings);
3333
}, [realm, globalSettings]);
3434

3535
return (

src/start/AuthScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class AuthScreenInner extends PureComponent<Props> {
295295
id_token: credential.identityToken,
296296
});
297297

298-
openLinkEmbedded(new URL(`/complete/apple/?${params}`, serverSettings.realm_uri).toString());
298+
openLinkEmbedded(new URL(`/complete/apple/?${params}`, serverSettings.realm_uri));
299299

300300
// Currently, the rest is handled with the `zulip://` redirect,
301301
// same as in the web flow.

src/start/CompatibilityScreen.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ function GooglePlayBadge() {
4747
}
4848

4949
export default class CompatibilityScreen extends PureComponent<{||}> {
50-
storeURL: string =
50+
storeURL: URL =
5151
Platform.OS === 'ios'
52-
? 'https://itunes.apple.com/app/zulip/id1203036395'
53-
: 'https://play.google.com/store/apps/details?id=com.zulipmobile';
52+
? new URL('https://itunes.apple.com/app/zulip/id1203036395')
53+
: new URL('https://play.google.com/store/apps/details?id=com.zulipmobile');
5454

5555
openStoreURL: () => void = () => {
5656
openLinkExternal(this.storeURL);

src/start/webAuth.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ export const generateRandomToken = async (): Promise<string> => {
4747
// in its response to protect against credentials intercept
4848
export const generateOtp = async (): Promise<string> => generateRandomToken();
4949

50+
// TODO: Take URL object instead of string (but make a copy on which to
51+
// mutate `searchParams`)
5052
export const openBrowser = (url: string, otp: string) => {
51-
openLinkEmbedded(`${url}?mobile_flow_otp=${otp}`);
53+
const urlCopy = new URL(url);
54+
urlCopy.searchParams.set('mobile_flow_otp', otp);
55+
openLinkEmbedded(urlCopy);
5256
};
5357

5458
export const closeBrowser = () => {

0 commit comments

Comments
 (0)