Skip to content

Commit

Permalink
msglist: Catch invalid-URL error on link long-press
Browse files Browse the repository at this point in the history
Fixes: zulip#5854
  • Loading branch information
chrisbobbe authored and gnprice committed Apr 25, 2024
1 parent 2fd4419 commit ae4cf01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/webview/handleOutboundEvents.js
Expand Up @@ -6,7 +6,7 @@ import * as api from '../api';
import config from '../config';
import type { UserId } from '../types';
import type { JSONableDict } from '../utils/jsonable';
import { showErrorAlert, showToast } from '../utils/info';
import { showConfirmationDialog, showErrorAlert, showToast } from '../utils/info';
import { pmKeyRecipientsFromMessage } from '../utils/recipient';
import { isUrlAnImage, tryParseUrl } from '../utils/url';
import * as logging from '../utils/logging';
Expand Down Expand Up @@ -209,8 +209,23 @@ const handleLongPress = (args: {|
const { _ } = props;

if (href !== null) {
const url = new URL(href, props.backgroundData.auth.realm).toString();
Clipboard.setString(url);
const url = tryParseUrl(href, props.backgroundData.auth.realm);
if (url == null) {
showConfirmationDialog({
title: 'Copy invalid link',
message: {
text: 'This link appears to be invalid. Do you want to copy it anyway?\n\n{text}',
values: { text: href },
},
onPressConfirm: () => {
Clipboard.setString(href);
showToast(_('Text copied'));
},
_,
});
return;
}
Clipboard.setString(url.toString());
showToast(_('Link copied'));
return;
}
Expand Down
3 changes: 3 additions & 0 deletions static/translations/messages_en.json
Expand Up @@ -184,6 +184,9 @@
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Copied": "Copied",
"Copy invalid link": "Copy invalid link",
"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}",
"Text copied": "Text copied",
"Link copied": "Link copied",
"This time is in your timezone. Original text was “{originalText}”.": "This time is in your timezone. Original text was “{originalText}”.",
"Mute topic": "Mute topic",
Expand Down

0 comments on commit ae4cf01

Please sign in to comment.