allow opening of files in webview (#305)

This commit is contained in:
Jonathan Cuthbert 2016-07-20 12:08:12 -05:00 committed by Guillermo Rauch
parent c75d5dedd0
commit a2363c52bd
2 changed files with 16 additions and 40 deletions

View file

@ -4,47 +4,23 @@ export const domainRegex = /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)
export default function isUrlCommand (shell, data) {
const matcher = regex[shell];
if (undefined === matcher) return null;
let url, i;
if (undefined === matcher || !data) return null;
switch (matcher) {
case regex.bash:
i = 5;
break;
const match = data.match(matcher);
if (!match) return null;
const protocol = match[1];
const path = match[2];
case regex.zsh:
i = 7;
break;
case regex.fish:
i = 4;
break;
}
let match = data.match(matcher);
if (match) {
url = match[i];
if (url) {
// extract the domain portion from the url
const domain = url.split('/')[0];
if (domainRegex.test(domain)) {
return toURL(url);
}
if (path) {
if (protocol) {
return `${protocol}${path}`;
}
// extract the domain portion from the url
const domain = path.split('/')[0];
if (domainRegex.test(domain)) {
return `http://${path}`;
}
}
return null;
}
function toURL (domain) {
if (/^https?:\/\//.test(domain)) {
return domain;
}
if ('//' === domain.substr(0, 2)) {
return domain;
}
return 'http://' + domain;
}

View file

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