Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if ssh url is valid #7613

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/index.ts
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
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