Skip to content

Commit 3ef29a7

Browse files
check if ssh url is valid
1 parent 2a7bb18 commit 3ef29a7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

app/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {gitDescribe} from 'git-describe';
3232
import parseUrl from 'parse-url';
3333

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

239240
app.on('open-url', (_event, sshUrl) => {
240241
GetWindow((win: BrowserWindow) => {
241-
win.rpc.emit('open ssh', parseUrl(sshUrl));
242+
try {
243+
win.rpc.emit('open ssh', parseUrl(sshUrl));
244+
} catch (e) {
245+
notify('Invalid ssh url', 'Please check your ssh url and try again.', {error: e});
246+
}
242247
});
243248
});

lib/actions/ui.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ export function openSSH(parsedUrl: ReturnType<typeof parseUrl>) {
300300
dispatch({
301301
type: UI_OPEN_SSH_URL,
302302
effect() {
303+
const resourseIsValid = /^[a-zA-Z0-9.-]+$/.test(parsedUrl.resource);
304+
if (!resourseIsValid) {
305+
notify('Invalid ssh url', 'Please check your ssh url and try again.');
306+
return;
307+
}
308+
303309
let command = `${parsedUrl.protocol} ${parsedUrl.user ? `${parsedUrl.user}@` : ''}${parsedUrl.resource}`;
304310

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

0 commit comments

Comments
 (0)