Skip to content

Commit

Permalink
check if ssh url is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
LabhanshAgrawal committed Nov 22, 2023
1 parent b020857 commit d3281ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {gitDescribe} from 'git-describe';
import parseUrl from 'parse-url';

import * as AppMenu from './menus/menu';
import notify from './notify';
import * as plugins from './plugins';
import {newWindow} from './ui/window';
import {installCLI} from './utils/cli-install';
Expand Down Expand Up @@ -238,6 +239,10 @@ app.on('open-file', (_event, path) => {

app.on('open-url', (_event, sshUrl) => {
GetWindow((win: BrowserWindow) => {
win.rpc.emit('open ssh', parseUrl(sshUrl));
try {
win.rpc.emit('open ssh', parseUrl(sshUrl));
} catch (e) {
notify('Invalid ssh url', 'Please check your ssh url and try again.', {error: e});
}
});
});
6 changes: 6 additions & 0 deletions lib/actions/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ export function openSSH(parsedUrl: ReturnType<typeof parseUrl>) {
dispatch({
type: UI_OPEN_SSH_URL,
effect() {
const resourseIsValid = /^[a-zA-Z0-9.-]+$/.test(parsedUrl.resource);
if (!resourseIsValid) {
notify('Invalid ssh url', 'Please check your ssh url and try again.');
return;
}

let command = `${parsedUrl.protocol} ${parsedUrl.user ? `${parsedUrl.user}@` : ''}${parsedUrl.resource}`;

if (parsedUrl.port) command += ` -p ${parsedUrl.port}`;
Expand Down

0 comments on commit d3281ca

Please sign in to comment.