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

Fix url interpretation #1259

Merged
merged 2 commits into from Dec 17, 2016
Merged
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
4 changes: 2 additions & 2 deletions lib/actions/sessions.js
@@ -1,5 +1,5 @@
import rpc from '../rpc';
import getURL from '../utils/url-command';
import isUrl from '../utils/url-command';
import {keys} from '../utils/object';
import findBySession from '../utils/term-groups';
import {
Expand Down Expand Up @@ -56,7 +56,7 @@ export function addSessionData(uid, data) {
const {shell} = getState().sessions.sessions[uid];

const enterKey = Boolean(data.match(/\n/));
const url = enterKey ? getURL(shell, data) : null;
const url = enterKey ? isUrl(shell, data) : null;

if (url) {
dispatch({
Expand Down
20 changes: 3 additions & 17 deletions lib/utils/url-command.js
@@ -1,30 +1,16 @@
import * as regex from './url-regex';

export const domainRegex = /([0-9]+[:.]*)+|([a-zA-Z0-9.]+[.][a-zA-Z0-9]+([:][0-9]+)*){1}/;

export default function isUrlCommand(shell, data) {
const matcher = regex[shell]; // eslint-disable-line import/namespace
if (undefined === matcher || !data) {
return null;
}

const match = data.match(matcher);
if (!match) {
return null;
}
const protocol = match[1];
const path = match[2];
const urlRegex = /((?:https?:\/\/)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)/;

if (path) {
if (protocol) {
return `${protocol}${path}`;
}
// extract the domain portion from the url
const domain = path.split('/')[0];
if (domainRegex.test(domain)) {
const result = path.match(domainRegex)[0];
return `http://${result}`;
}
if (match && urlRegex.test(match[2])) {
return `${match[2]}`;
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/url-regex.js
@@ -1,4 +1,4 @@
export const sh = /(?:ba)?sh: ((?:https?:\/\/)|(?:file:\/\/)|(?:\/\/))?(.*): (?:(?:command not found)|(?:No such file or directory))/;
export const sh = /(?:ba)?sh: ((?:file:\/\/)|(?:\/\/))?(.*): (?:(?:command not found)|(?:No such file or directory))/;
export const bash = sh;
export const zsh = /zsh: (?:(?:command not found)|(?:no such file or directory)): ((?:https?:\/\/)|(?:file:\/\/)|(?:\/\/))?([^\n]+)/;
export const fish = /fish: Unknown command '((?:https?:\/\/)|(?:file:\/\/)|(?:\/\/))?([^']+)'/;
export const zsh = /zsh: (?:(?:command not found)|(?:no such file or directory)): ((?:file:\/\/)|(?:\/\/))?([^\n]+)/;
export const fish = /fish: Unknown command '((?:file:\/\/)|(?:\/\/))?([^']+)'/;