Skip to content

Commit

Permalink
LSNBLDR-680; fix check for valid integer in maxpoints (sakaiproject#3012
Browse files Browse the repository at this point in the history
)
  • Loading branch information
clhedrick authored Jul 11, 2016
1 parent ab56a02 commit 1067ed8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7013,7 +7013,9 @@ public String updateQuestion() {
pointsInt = Integer.valueOf(maxPoints);
}catch(Exception ex) {
setErrMessage(messageLocator.getMessage("simplepage.integer-expected"));
return "failure";
// can't fail, because it will leave an inconsistent items. So create one with default point value
// check in UI to make sure it can't happen
// return "failure";
}
}

Expand Down
1 change: 1 addition & 0 deletions lessonbuilder/tool/src/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ simplepage.comments-anonymous=Keep Comments Anonymous
simplepage.comments-graded=Create Gradebook items for these
simplepage.comments-max=Maximum points:
simplepage.integer-expected=Points must be set to a valid number.
simplepage.integer-too-big=Points must be less than 2147483648.
simplepage.gbname-expected=Gradebook item name must be supplied.
simplepage.comment-delete=Delete comment from {}
simplepage.delete_comment_confirm=Are you sure you want to delete this comment written by {}?
Expand Down
40 changes: 31 additions & 9 deletions lessonbuilder/tool/src/webapp/js/show-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,32 @@ function checkgroups(elt, groups) {
}
}

function safeParseFloat(s) {
if (!/^[0-9.]+$/.test(s))
// maxpoints is an Integer. Actually in GB it's float, but
// our code in SimplePageBean parses the string as Integer, so make
// sure it's OK. At least according to ecmascript, parseInt will do
// weird things if the value is >= 2^31. It is impossible to catch
// this with numerical functions, so I have to do string comparison
// 2^31 is 2147483648. length is 10
function safeParseInt(s) {
if (!/^[0-9]+$/.test(s))
return NaN;
return parseFloat(s);
if (s.length > 10) {
return Infinity;
}
if (s.length === 10) {
if (s >= "2147483648") {
return Infinity;
}
}
return parseInt(s);
}
// get the right error message. called when ifFinite(i) returns false
// that happens if it is not a number or is too big
function intError(i) {
if (isNaN(i))
return msg("simplepage.integer-expected");
else
return msg('simplepage.integer-too-big');
}

var blankRubricTemplate, blankRubricRow;
Expand Down Expand Up @@ -2554,8 +2576,8 @@ function checkEditTitleForm() {
$('#edit-title-error').text(msg("simplepage.title_notblank"));
$('#edit-title-error-container').show();
return false;
}else if ($("#page-gradebook").prop("checked") && !isFinite(safeParseFloat($("#page-points").val()))) {
$('#edit-title-error').text(msg("simplepage.integer-expected"));
}else if ($("#page-gradebook").prop("checked") && !isFinite(safeParseInt($("#page-points").val()))) {
$('#edit-title-error').text(intError(safeParseInt($("#page-points").val())));
$('#edit-title-error-container').show();
}else {
$('#edit-title-error-container').hide();
Expand Down Expand Up @@ -2696,8 +2718,8 @@ function checkEditItemForm() {
$('#edit-item-error-container').show();
return false;
} else if ((requirementType === '3' || requirementType === '6') &&
$("#item-required2").prop("checked") && !isFinite(safeParseFloat($("#assignment-points").val()))) {
$('#edit-item-error').text(msg("simplepage.integer-expected"));
$("#item-required2").prop("checked") && !isFinite(safeParseInt($("#assignment-points").val()))) {
$('#edit-item-error').text(intError(safeParseInt($("#assignment-points").val())));
$('#edit-item-error-container').show();
return false;
}else {
Expand Down Expand Up @@ -3052,8 +3074,8 @@ function checkQuestionGradedForm() {

// Prepares the question dialog to be submitted
function prepareQuestionDialog() {
if ($("#question-graded").prop("checked") && !isFinite(safeParseFloat($("#question-max").val()))) {
$('#question-error').text(msg("simplepage.integer-expected"));
if ($("#question-graded").prop("checked") && !isFinite(safeParseInt($("#question-max").val()))) {
$('#question-error').text(intError(safeParseInt($("#question-max").val())));
$('#question-error-container').show();
return false;
} else if($("#question-graded").prop("checked") && $("#question-gradebook-title").val() === '') {
Expand Down
1 change: 1 addition & 0 deletions lessonbuilder/tool/src/webapp/templates/ShowPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ <h3 class="questionText" rsf:id="questionText"></h3>
<p rsf:id="msg=simplepage.site" id="simplepage.site"></p>
<p rsf:id="msg=simplepage.system" id="simplepage.system"></p>
<p rsf:id="msg=simplepage.integer-expected" id="simplepage.integer-expected"></p>
<p rsf:id="msg=simplepage.integer-too-big" id="simplepage.integer-too-big"></p>
<p rsf:id="msg=simplepage.gbname-expected" id="simplepage.gbname-expected"></p>
<p rsf:id="msg=simplepage.width-height" id="simplepage.width-height"></p>
<p rsf:id="msg=simplepage.nothing-over-100-percent" id="simplepage.nothing-over-100-percent"></p>
Expand Down

0 comments on commit 1067ed8

Please sign in to comment.