diff --git a/model/command.go b/model/command.go
index 4d5f7ace99..decb647b70 100644
--- a/model/command.go
+++ b/model/command.go
@@ -6,11 +6,14 @@ package model
import (
"encoding/json"
"io"
+ "strings"
)
const (
COMMAND_METHOD_POST = "P"
COMMAND_METHOD_GET = "G"
+ MIN_TRIGGER_LENGTH = 1
+ MAX_TRIGGER_LENGTH = 128
)
type Command struct {
@@ -99,7 +102,7 @@ func (o *Command) IsValid() *AppError {
return NewLocAppError("Command.IsValid", "model.command.is_valid.team_id.app_error", nil, "")
}
- if len(o.Trigger) == 0 || len(o.Trigger) > 128 {
+ if len(o.Trigger) < MIN_TRIGGER_LENGTH || len(o.Trigger) > MAX_TRIGGER_LENGTH || strings.Index(o.Trigger, "/") == 0 || strings.Contains(o.Trigger, " ") {
return NewLocAppError("Command.IsValid", "model.command.is_valid.trigger.app_error", nil, "")
}
diff --git a/webapp/components/backstage/add_command.jsx b/webapp/components/backstage/add_command.jsx
index f3208bc5f5..c817764aab 100644
--- a/webapp/components/backstage/add_command.jsx
+++ b/webapp/components/backstage/add_command.jsx
@@ -11,6 +11,7 @@ import {FormattedMessage} from 'react-intl';
import FormError from 'components/form_error.jsx';
import {browserHistory, Link} from 'react-router';
import SpinnerButton from 'components/spinner_button.jsx';
+import Constants from 'utils/constants.jsx';
const REQUEST_POST = 'P';
const REQUEST_GET = 'G';
@@ -92,6 +93,51 @@ export default class AddCommand extends React.Component {
return;
}
+ if (command.trigger.indexOf('/') === 0) {
+ this.setState({
+ saving: false,
+ clientError: (
+
+ )
+ });
+
+ return;
+ }
+
+ if (command.trigger.indexOf(' ') !== -1) {
+ this.setState({
+ saving: false,
+ clientError: (
+
+ )
+ });
+ return;
+ }
+
+ if (command.trigger.length < Constants.MIN_TRIGGER_LENGTH || command.trigger.length > Constants.MAX_TRIGGER_LENGTH) {
+ this.setState({
+ saving: false,
+ clientError: (
+
+ )
+ });
+
+ return;
+ }
+
if (!command.url) {
this.setState({
saving: false,
@@ -323,7 +369,7 @@ export default class AddCommand extends React.Component {