[MM-52587] Clean up URL utils, use isInternalURL when possible (#2702)
This commit is contained in:
@@ -7,6 +7,9 @@ import classNames from 'classnames';
|
||||
|
||||
import {MattermostTeam} from 'types/config';
|
||||
|
||||
import {isValidURL, parseURL} from 'common/utils/url';
|
||||
import {MODAL_TRANSITION_TIMEOUT} from 'common/utils/constants';
|
||||
|
||||
import womanLaptop from 'renderer/assets/svg/womanLaptop.svg';
|
||||
|
||||
import Header from 'renderer/components/Header';
|
||||
@@ -14,9 +17,6 @@ import Input, {STATUS, SIZE} from 'renderer/components/Input';
|
||||
import LoadingBackground from 'renderer/components/LoadingScreen/LoadingBackground';
|
||||
import SaveButton from 'renderer/components/SaveButton/SaveButton';
|
||||
|
||||
import {MODAL_TRANSITION_TIMEOUT} from 'common/utils/constants';
|
||||
import urlUtils from 'common/utils/url';
|
||||
|
||||
import 'renderer/css/components/Button.scss';
|
||||
import 'renderer/css/components/ConfigureServer.scss';
|
||||
import 'renderer/css/components/LoadingScreen.css';
|
||||
@@ -72,7 +72,7 @@ function ConfigureServer({
|
||||
}, []);
|
||||
|
||||
const checkProtocolInURL = (checkURL: string): Promise<string> => {
|
||||
if (urlUtils.startsWithProtocol(checkURL)) {
|
||||
if (isValidURL(checkURL)) {
|
||||
return Promise.resolve(checkURL);
|
||||
}
|
||||
return window.desktop.modals.pingDomain(checkURL).
|
||||
@@ -115,21 +115,21 @@ function ConfigureServer({
|
||||
});
|
||||
}
|
||||
|
||||
if (!urlUtils.startsWithProtocol(fullURL)) {
|
||||
return formatMessage({
|
||||
id: 'renderer.components.newTeamModal.error.urlNeedsHttp',
|
||||
defaultMessage: 'URL should start with http:// or https://.',
|
||||
});
|
||||
}
|
||||
|
||||
if (!urlUtils.isValidURL(fullURL)) {
|
||||
if (!parseURL(fullURL)) {
|
||||
return formatMessage({
|
||||
id: 'renderer.components.newTeamModal.error.urlIncorrectFormatting',
|
||||
defaultMessage: 'URL is not formatted correctly.',
|
||||
});
|
||||
}
|
||||
|
||||
if (currentTeams.find(({url: existingURL}) => existingURL === fullURL)) {
|
||||
if (!isValidURL(fullURL)) {
|
||||
return formatMessage({
|
||||
id: 'renderer.components.newTeamModal.error.urlNeedsHttp',
|
||||
defaultMessage: 'URL should start with http:// or https://.',
|
||||
});
|
||||
}
|
||||
|
||||
if (currentTeams.find(({url: existingURL}) => parseURL(existingURL)?.toString === parseURL(fullURL)?.toString())) {
|
||||
return formatMessage({
|
||||
id: 'renderer.components.newTeamModal.error.serverUrlExists',
|
||||
defaultMessage: 'A server with the same URL already exists.',
|
||||
|
@@ -8,7 +8,7 @@ import {FormattedMessage, injectIntl, IntlShape} from 'react-intl';
|
||||
|
||||
import {MattermostTeam} from 'types/config';
|
||||
|
||||
import urlUtils from 'common/utils/url';
|
||||
import {isValidURL} from 'common/utils/url';
|
||||
|
||||
type Props = {
|
||||
onClose?: () => void;
|
||||
@@ -124,7 +124,7 @@ class NewTeamModal extends React.PureComponent<Props, State> {
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (!urlUtils.isValidURL(this.state.teamUrl.trim())) {
|
||||
if (!isValidURL(this.state.teamUrl.trim())) {
|
||||
return (
|
||||
<FormattedMessage
|
||||
id='renderer.components.newTeamModal.error.urlIncorrectFormatting'
|
||||
|
@@ -10,7 +10,7 @@ import {AuthenticationResponseDetails, AuthInfo} from 'electron/renderer';
|
||||
|
||||
import {LoginModalInfo} from 'types/modals';
|
||||
|
||||
import urlUtils from 'common/utils/url';
|
||||
import {parseURL} from 'common/utils/url';
|
||||
|
||||
type Props = {
|
||||
onCancel: (request: AuthenticationResponseDetails) => void;
|
||||
@@ -86,7 +86,7 @@ class LoginModal extends React.PureComponent<Props, State> {
|
||||
/>
|
||||
);
|
||||
}
|
||||
const tmpURL = urlUtils.parseURL(this.state.request.url);
|
||||
const tmpURL = parseURL(this.state.request.url);
|
||||
return (
|
||||
<FormattedMessage
|
||||
id='renderer.modals.login.loginModal.message.server'
|
||||
|
@@ -7,9 +7,9 @@ import {FormattedMessage, injectIntl, IntlShape} from 'react-intl';
|
||||
|
||||
import {PermissionModalInfo} from 'types/modals';
|
||||
|
||||
import urlUtil from 'common/utils/url';
|
||||
import {t} from 'common/utils/util';
|
||||
import {PERMISSION_DESCRIPTION} from 'common/permissions';
|
||||
import {parseURL} from 'common/utils/url';
|
||||
|
||||
type Props = {
|
||||
handleDeny: React.MouseEventHandler<HTMLButtonElement>;
|
||||
@@ -51,14 +51,14 @@ class PermissionModal extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
const {url, permission} = this.state;
|
||||
const originDisplay = url ? urlUtil.getHost(url) : this.props.intl.formatMessage({id: 'renderer.modals.permission.permissionModal.unknownOrigin', defaultMessage: 'unknown origin'});
|
||||
const originLink = url ? originDisplay : '';
|
||||
const originDisplay = url ? parseURL(url)?.origin : this.props.intl.formatMessage({id: 'renderer.modals.permission.permissionModal.unknownOrigin', defaultMessage: 'unknown origin'});
|
||||
const originLink = originDisplay ?? '';
|
||||
|
||||
const click = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
||||
e.preventDefault();
|
||||
let parseUrl;
|
||||
try {
|
||||
parseUrl = urlUtil.parseURL(originLink);
|
||||
parseUrl = parseURL(originLink);
|
||||
this.props.openExternalLink(parseUrl!.protocol, originLink);
|
||||
} catch (err) {
|
||||
console.error(`invalid url ${originLink} supplied to externallink: ${err}`);
|
||||
|
Reference in New Issue
Block a user