From 8bfab922130b8e0f4e00fee1a65d8358d59edd47 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 16 Jan 2020 16:38:49 +1100 Subject: [PATCH] add regex url check before joining channel --- stylesheets/_session.scss | 2 +- ts/components/session/LeftPaneChannelSection.tsx | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/stylesheets/_session.scss b/stylesheets/_session.scss index 7e4188958..b50d3c31c 100644 --- a/stylesheets/_session.scss +++ b/stylesheets/_session.scss @@ -503,7 +503,7 @@ label { .message-selection-overlay { display: none; position: absolute; - right: 15px; + right: 10px; left: 15px; .close-button { diff --git a/ts/components/session/LeftPaneChannelSection.tsx b/ts/components/session/LeftPaneChannelSection.tsx index 2345a653c..a556165c2 100644 --- a/ts/components/session/LeftPaneChannelSection.tsx +++ b/ts/components/session/LeftPaneChannelSection.tsx @@ -302,6 +302,8 @@ export class LeftPaneChannelSection extends React.Component { return false; } + const regexURL = /(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?/; + if (channelUrlPasted.length <= 0) { window.pushToast({ title: window.i18n('noServerURL'), @@ -312,6 +314,16 @@ export class LeftPaneChannelSection extends React.Component { return false; } + if (!regexURL.test(channelUrlPasted)) { + window.pushToast({ + title: window.i18n('noServerURL'), + type: 'error', + id: 'connectToServerFail', + }); + + return false; + } + // TODO: Make this not hard coded const channelId = 1; this.setState({ loading: true });