FIX: Infinite loop when poll step is zero (#5380)

* Fix infinite loop when poll step is zero

* Add test for step minimum and for breaking test

* Remove trailing spaces (eslint)

* Remove extra space (eslint)

* Removed test call .twice
This commit is contained in:
Eric Berry
2017-11-30 09:04:41 -07:00
committed by Régis Hanol
parent 3f8d0c5c94
commit ab22c8cad4
5 changed files with 33 additions and 2 deletions

View File

@ -87,7 +87,10 @@ export default Ember.Controller.extend({
if (isMultiple) {
return this._comboboxOptions(pollMinInt + 1, count + 1);
} else if (isNumber) {
const pollStepInt = parseInt(pollStep) || 1;
let pollStepInt = parseInt(pollStep, 10);
if (pollStepInt < 1) {
pollStepInt = 1;
}
return this._comboboxOptions(pollMinInt + 1, pollMinInt + (this.siteSettings.poll_maximum_options * pollStepInt));
}
},
@ -109,10 +112,15 @@ export default Ember.Controller.extend({
pollHeader += ` name=poll${match.length + 1}`;
};
let step = pollStep;
if (step < 1) {
step = 1;
}
if (pollType) pollHeader += ` type=${pollType}`;
if (pollMin && showMinMax) pollHeader += ` min=${pollMin}`;
if (pollMax) pollHeader += ` max=${pollMax}`;
if (isNumber) pollHeader += ` step=${pollStep}`;
if (isNumber) pollHeader += ` step=${step}`;
if (publicPoll) pollHeader += ' public=true';
pollHeader += ']';
output += `${pollHeader}\n`;
@ -143,6 +151,17 @@ export default Ember.Controller.extend({
return InputValidation.create(options);
},
@computed("pollStep")
minStepValueValidation(pollStep) {
let options = { ok: true };
if (pollStep < 1) {
options = { failed: true, reason: I18n.t("poll.ui_builder.help.min_step_value") };
}
return InputValidation.create(options);
},
@computed("disableInsert")
minNumOfOptionsValidation(disableInsert) {
let options = { ok: true };