Check URL parameters via regexp

Signed-off-by: Jeffrey Morgan <jmorganca@gmail.com>
This commit is contained in:
Jeffrey Morgan 2015-04-14 13:26:27 -04:00
parent 902a0e5763
commit 6679f9a851
3 changed files with 33 additions and 18 deletions

View File

@ -7,6 +7,7 @@ var util = require('./Util');
var metrics = require('./Metrics');
var Router = require('react-router');
var ContainerStore = require('./ContainerStore');
var dialog = require('remote').require('dialog');
var ContainerHomeFolder = React.createClass({
mixins: [Router.State, Router.Navigation],
@ -16,6 +17,11 @@ var ContainerHomeFolder = React.createClass({
});
if (hostVolume.indexOf(process.env.HOME) === -1) {
dialog.showMessageBox({
message: 'Enable all volumes to edit files via Finder? This may not work with all database containers.',
buttons: ['Enable Volumes', 'Cancel']
}, (index) => {
if (index === 0) {
var volumes = _.clone(this.props.container.Volumes);
var newHostVolume = path.join(util.home(), 'Kitematic', this.props.container.Name, containerVolume);
volumes[containerVolume] = newHostVolume;
@ -24,13 +30,15 @@ var ContainerHomeFolder = React.createClass({
});
ContainerStore.updateContainer(this.props.container.Name, {
Binds: binds
}, function (err) {
}, (err) => {
if (err) {
console.log(err);
return;
}
shell.showItemInFolder(newHostVolume);
});
}
});
} else {
shell.showItemInFolder(hostVolume);
}

View File

@ -34,6 +34,8 @@ ipc.on('application:quitting', opts => {
});
ipc.on('application:open-url', opts => {
var repoRegexp = /[a-z0-9]+(?:[._-][a-z0-9]+)*/;
var tagRegexp = /[\w][\w.-]{0,127}/;
var parser = document.createElement('a');
parser.href = opts.url;
@ -44,10 +46,15 @@ ipc.on('application:open-url', opts => {
var pathname = parser.pathname.replace('//', '');
var tokens = pathname.split('/');
var type = tokens[0];
var method = tokens[1];
var repo = tokens.slice(2).join('/');
if (type === 'repository' && method === 'run') {
ContainerStore.setPending(repo, parser.tag || 'latest');
var repo = tokens.slice(1).join('/');
var tag = parser.tag || 'latest';
if (repo.indexOf('/') !== -1 || !repoRegexp.test(repo) || !tagRegexp.test(tag)) {
return;
}
if (type === 'repository') {
ContainerStore.setPending(repo, tag);
}
});

View File

@ -29,7 +29,7 @@ module.exports = React.createClass({
<div className="details">
<div className="new-container-pull">
<div className="content">
<h1>You&#39;re about to download <a onClick={this.handleOpenClick}>{this.props.pending.repository}</a>.</h1>
<h1>You&#39;re about to download and run <a onClick={this.handleOpenClick}>{this.props.pending.repository}:{this.props.pending.tag}</a>.</h1>
<h1>Please confirm to create the container.</h1>
<div className="buttons">
<a className="btn btn-action" onClick={this.handleCancelClick}>Cancel</a> <a onClick={this.handleConfirmClick} className="btn btn-action">Confirm</a>