Skip to content

Commit ae4cf01

Browse files
chrisbobbegnprice
authored andcommitted
msglist: Catch invalid-URL error on link long-press
Fixes: zulip#5854
1 parent 2fd4419 commit ae4cf01

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/webview/handleOutboundEvents.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as api from '../api';
66
import config from '../config';
77
import type { UserId } from '../types';
88
import type { JSONableDict } from '../utils/jsonable';
9-
import { showErrorAlert, showToast } from '../utils/info';
9+
import { showConfirmationDialog, showErrorAlert, showToast } from '../utils/info';
1010
import { pmKeyRecipientsFromMessage } from '../utils/recipient';
1111
import { isUrlAnImage, tryParseUrl } from '../utils/url';
1212
import * as logging from '../utils/logging';
@@ -209,8 +209,23 @@ const handleLongPress = (args: {|
209209
const { _ } = props;
210210

211211
if (href !== null) {
212-
const url = new URL(href, props.backgroundData.auth.realm).toString();
213-
Clipboard.setString(url);
212+
const url = tryParseUrl(href, props.backgroundData.auth.realm);
213+
if (url == null) {
214+
showConfirmationDialog({
215+
title: 'Copy invalid link',
216+
message: {
217+
text: 'This link appears to be invalid. Do you want to copy it anyway?\n\n{text}',
218+
values: { text: href },
219+
},
220+
onPressConfirm: () => {
221+
Clipboard.setString(href);
222+
showToast(_('Text copied'));
223+
},
224+
_,
225+
});
226+
return;
227+
}
228+
Clipboard.setString(url.toString());
214229
showToast(_('Link copied'));
215230
return;
216231
}

static/translations/messages_en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@
184184
"Add a reaction": "Add a reaction",
185185
"Copy to clipboard": "Copy to clipboard",
186186
"Copied": "Copied",
187+
"Copy invalid link": "Copy invalid link",
188+
"This link appears to be invalid. Do you want to copy it anyway?\n\n{text}": "This link appears to be invalid. Do you want to copy it anyway?\n\n{text}",
189+
"Text copied": "Text copied",
187190
"Link copied": "Link copied",
188191
"This time is in your timezone. Original text was “{originalText}”.": "This time is in your timezone. Original text was “{originalText}”.",
189192
"Mute topic": "Mute topic",

0 commit comments

Comments
 (0)