Fix url interpretation (#1259)

* Fix url interpretation

* update regex
This commit is contained in:
Philippe Potvin 2016-12-17 17:17:58 -05:00 committed by Guillermo Rauch
parent 25fcf3a6a4
commit b2f67c73e4
3 changed files with 8 additions and 22 deletions

View file

@ -1,5 +1,5 @@
import rpc from '../rpc'; import rpc from '../rpc';
import getURL from '../utils/url-command'; import isUrl from '../utils/url-command';
import {keys} from '../utils/object'; import {keys} from '../utils/object';
import findBySession from '../utils/term-groups'; import findBySession from '../utils/term-groups';
import { import {
@ -56,7 +56,7 @@ export function addSessionData(uid, data) {
const {shell} = getState().sessions.sessions[uid]; const {shell} = getState().sessions.sessions[uid];
const enterKey = Boolean(data.match(/\n/)); const enterKey = Boolean(data.match(/\n/));
const url = enterKey ? getURL(shell, data) : null; const url = enterKey ? isUrl(shell, data) : null;
if (url) { if (url) {
dispatch({ dispatch({

View file

@ -1,7 +1,5 @@
import * as regex from './url-regex'; 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) { export default function isUrlCommand(shell, data) {
const matcher = regex[shell]; // eslint-disable-line import/namespace const matcher = regex[shell]; // eslint-disable-line import/namespace
if (undefined === matcher || !data) { if (undefined === matcher || !data) {
@ -9,22 +7,10 @@ export default function isUrlCommand(shell, data) {
} }
const match = data.match(matcher); const match = data.match(matcher);
if (!match) { const urlRegex = /((?:https?:\/\/)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)/;
return null;
}
const protocol = match[1];
const path = match[2];
if (path) { if (match && urlRegex.test(match[2])) {
if (protocol) { return `${match[2]}`;
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}`;
}
} }
return null; return null;

View file

@ -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 bash = sh;
export const zsh = /zsh: (?:(?:command not found)|(?:no such file or directory)): ((?:https?:\/\/)|(?:file:\/\/)|(?:\/\/))?([^\n]+)/; export const zsh = /zsh: (?:(?:command not found)|(?:no such file or directory)): ((?:file:\/\/)|(?:\/\/))?([^\n]+)/;
export const fish = /fish: Unknown command '((?:https?:\/\/)|(?:file:\/\/)|(?:\/\/))?([^']+)'/; export const fish = /fish: Unknown command '((?:file:\/\/)|(?:\/\/))?([^']+)'/;