mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-21 21:01:29 +01:00
Safe Link: Fix opening links with no protocol (#1556)
This commit is contained in:
parent
50865c78f5
commit
eed0934c0a
@ -6,6 +6,7 @@ import {
|
||||
DEBUG, RE_TG_LINK, RE_TME_LINK,
|
||||
} from '../../config';
|
||||
import buildClassName from '../../util/buildClassName';
|
||||
import { ensureProtocol } from '../../util/ensureProtocol';
|
||||
|
||||
type OwnProps = {
|
||||
url?: string;
|
||||
@ -72,14 +73,6 @@ const SafeLink: FC<OwnProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
function ensureProtocol(url?: string) {
|
||||
if (!url) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return url.includes('://') ? url : `https://${url}`;
|
||||
}
|
||||
|
||||
function getDomain(url?: string) {
|
||||
if (!url) {
|
||||
return undefined;
|
||||
|
@ -4,6 +4,7 @@ import { withGlobal } from '../../lib/teact/teactn';
|
||||
import { GlobalActions } from '../../global/types';
|
||||
|
||||
import { pick } from '../../util/iteratees';
|
||||
import { ensureProtocol } from '../../util/ensureProtocol';
|
||||
import renderText from '../common/helpers/renderText';
|
||||
import useLang from '../../hooks/useLang';
|
||||
import useCurrentOrPrev from '../../hooks/useCurrentOrPrev';
|
||||
@ -20,7 +21,7 @@ const SafeLinkModal: FC<OwnProps & DispatchProps> = ({ url, toggleSafeLinkModal
|
||||
const lang = useLang();
|
||||
|
||||
const handleOpen = useCallback(() => {
|
||||
window.open(url);
|
||||
window.open(ensureProtocol(url));
|
||||
toggleSafeLinkModal({ url: undefined });
|
||||
}, [toggleSafeLinkModal, url]);
|
||||
|
||||
|
@ -6,6 +6,7 @@ import { IAnchorPosition } from '../../../types';
|
||||
|
||||
import { EDITABLE_INPUT_ID } from '../../../config';
|
||||
import buildClassName from '../../../util/buildClassName';
|
||||
import { ensureProtocol } from '../../../util/ensureProtocol';
|
||||
import captureEscKeyListener from '../../../util/captureEscKeyListener';
|
||||
import useShowTransition from '../../../hooks/useShowTransition';
|
||||
import useVirtualBackdrop from '../../../hooks/useVirtualBackdrop';
|
||||
@ -280,7 +281,7 @@ const TextFormatter: FC<OwnProps> = ({
|
||||
]);
|
||||
|
||||
function handleLinkUrlConfirm() {
|
||||
const formattedLinkUrl = encodeURI(linkUrl.includes('://') ? linkUrl : `http://${linkUrl}`);
|
||||
const formattedLinkUrl = encodeURI(ensureProtocol(linkUrl) || '');
|
||||
|
||||
if (isEditingLink) {
|
||||
const element = getSelectedElement();
|
||||
|
9
src/util/ensureProtocol.ts
Normal file
9
src/util/ensureProtocol.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export function ensureProtocol(url?: string) {
|
||||
if (!url) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// HTTP was chosen by default as a fix for https://bugs.telegram.org/c/10712.
|
||||
// It is also the default protocol in the official TDesktop client.
|
||||
return url.includes('://') ? url : `http://${url}`;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user