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) { export default function isUrlCommand (shell, data) {
const matcher = regex[shell]; const matcher = regex[shell];
if (undefined === matcher) return null; if (undefined === matcher || !data) return null;
let url, i;
switch (matcher) { const match = data.match(matcher);
case regex.bash: if (!match) return null;
i = 5; const protocol = match[1];
break; const path = match[2];
case regex.zsh: if (path) {
i = 7; if (protocol) {
break; return `${protocol}${path}`;
}
case regex.fish: // extract the domain portion from the url
i = 4; const domain = path.split('/')[0];
break; if (domainRegex.test(domain)) {
} return `http://${path}`;
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);
}
} }
} }
return null; 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 bash = sh;
export const zsh = /zsh: ((command not found)|(no such file or directory)): ((https?:\/\/)|(\/\/))?([^\n]+)/; export const zsh = /zsh: (?:(?:command not found)|(?:no such file or directory)): ((?:https?:\/\/)|(?:file:\/\/)|(?:\/\/))?([^\n]+)/;
export const fish = /fish: Unknown command '((https?:\/\/)|(\/\/))?([^']+)'/; export const fish = /fish: Unknown command '((?:https?:\/\/)|(?:file:\/\/)|(?:\/\/))?([^']+)'/;