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:
parent
3f8d0c5c94
commit
ab22c8cad4
|
@ -87,7 +87,10 @@ export default Ember.Controller.extend({
|
||||||
if (isMultiple) {
|
if (isMultiple) {
|
||||||
return this._comboboxOptions(pollMinInt + 1, count + 1);
|
return this._comboboxOptions(pollMinInt + 1, count + 1);
|
||||||
} else if (isNumber) {
|
} 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));
|
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}`;
|
pollHeader += ` name=poll${match.length + 1}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let step = pollStep;
|
||||||
|
if (step < 1) {
|
||||||
|
step = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (pollType) pollHeader += ` type=${pollType}`;
|
if (pollType) pollHeader += ` type=${pollType}`;
|
||||||
if (pollMin && showMinMax) pollHeader += ` min=${pollMin}`;
|
if (pollMin && showMinMax) pollHeader += ` min=${pollMin}`;
|
||||||
if (pollMax) pollHeader += ` max=${pollMax}`;
|
if (pollMax) pollHeader += ` max=${pollMax}`;
|
||||||
if (isNumber) pollHeader += ` step=${pollStep}`;
|
if (isNumber) pollHeader += ` step=${step}`;
|
||||||
if (publicPoll) pollHeader += ' public=true';
|
if (publicPoll) pollHeader += ' public=true';
|
||||||
pollHeader += ']';
|
pollHeader += ']';
|
||||||
output += `${pollHeader}\n`;
|
output += `${pollHeader}\n`;
|
||||||
|
@ -143,6 +151,17 @@ export default Ember.Controller.extend({
|
||||||
return InputValidation.create(options);
|
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")
|
@computed("disableInsert")
|
||||||
minNumOfOptionsValidation(disableInsert) {
|
minNumOfOptionsValidation(disableInsert) {
|
||||||
let options = { ok: true };
|
let options = { ok: true };
|
||||||
|
|
|
@ -32,7 +32,9 @@
|
||||||
{{input type='number'
|
{{input type='number'
|
||||||
value=pollStep
|
value=pollStep
|
||||||
valueAttribute="value"
|
valueAttribute="value"
|
||||||
|
min="1"
|
||||||
class="poll-options-step"}}
|
class="poll-options-step"}}
|
||||||
|
{{input-tip validation=minStepValueValidation}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -133,6 +133,11 @@ const rule = {
|
||||||
let max = parseInt(attrs["max"], 10);
|
let max = parseInt(attrs["max"], 10);
|
||||||
let step = parseInt(attrs["step"], 10);
|
let step = parseInt(attrs["step"], 10);
|
||||||
|
|
||||||
|
// infinite loop if step < 1
|
||||||
|
if (step < 1) {
|
||||||
|
step = 1;
|
||||||
|
}
|
||||||
|
|
||||||
let header = [];
|
let header = [];
|
||||||
|
|
||||||
let token = new state.Token('poll_open', 'div', 1);
|
let token = new state.Token('poll_open', 'div', 1);
|
||||||
|
|
|
@ -75,6 +75,7 @@ en:
|
||||||
help:
|
help:
|
||||||
options_count: Enter at least 2 options
|
options_count: Enter at least 2 options
|
||||||
invalid_values: Minimum value must be smaller than the maximum value.
|
invalid_values: Minimum value must be smaller than the maximum value.
|
||||||
|
min_step_value: The minimum step value is 1
|
||||||
poll_type:
|
poll_type:
|
||||||
label: Type
|
label: Type
|
||||||
regular: Single Choice
|
regular: Single Choice
|
||||||
|
|
|
@ -196,6 +196,10 @@ test("number pollOutput", function(assert) {
|
||||||
controller.set("publicPoll", true);
|
controller.set("publicPoll", true);
|
||||||
|
|
||||||
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2 public=true]\n[/poll]", "it should return the right output");
|
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2 public=true]\n[/poll]", "it should return the right output");
|
||||||
|
|
||||||
|
controller.set("pollStep", 0);
|
||||||
|
|
||||||
|
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=1 public=true]\n[/poll]", "it should return the right output");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("regular pollOutput", function(assert) {
|
test("regular pollOutput", function(assert) {
|
||||||
|
|
Loading…
Reference in New Issue