FIX: don't allow adding a value containing vertical bar char to the secret list

This commit is contained in:
Maja Komel
2018-11-04 21:18:58 +01:00
parent cc9869a61b
commit ae9eddb002
5 changed files with 67 additions and 9 deletions

View File

@ -2,11 +2,10 @@ import { on } from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend({
classNameBindings: [":value-list", ":secret-value-list"],
inputInvalidKey: Ember.computed.empty("newKey"),
inputInvalidSecret: Ember.computed.empty("newSecret"),
inputDelimiter: null,
collection: null,
values: null,
validationMessage: null,
@on("didReceiveAttrs")
_setupCollection() {
@ -20,15 +19,18 @@ export default Ember.Component.extend({
actions: {
changeKey(index, newValue) {
if (this._checkInvalidInput(newValue)) return;
this._replaceValue(index, newValue, "key");
},
changeSecret(index, newValue) {
if (this._checkInvalidInput(newValue)) return;
this._replaceValue(index, newValue, "secret");
},
addValue() {
if (this.get("inputInvalidKey") || this.get("inputInvalidSecret")) return;
if (this._checkInvalidInput([this.get("newKey"), this.get("newSecret")]))
return;
this._addValue(this.get("newKey"), this.get("newSecret"));
this.setProperties({ newKey: "", newSecret: "" });
},
@ -38,6 +40,19 @@ export default Ember.Component.extend({
}
},
_checkInvalidInput(inputs) {
this.set("validationMessage", null);
for (let input of inputs) {
if (Ember.isEmpty(input) || input.includes("|")) {
this.set(
"validationMessage",
I18n.t("admin.site_settings.secret_list.invalid_input")
);
return true;
}
}
},
_addValue(value, secret) {
this.get("collection").addObject({ key: value, secret: secret });
this._saveValues();