Skip to content

Commit

Permalink
Fixed issue with HTML entities in character length count.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsharman committed Mar 8, 2024
1 parent fd03e46 commit ed8c1aa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
16 changes: 14 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@caspingus/lt",
"version": "2.7.0",
"version": "2.7.1",
"description": "A utility library of helpers and tools for working with Learnosity APIs.",
"main": "src/index.js",
"author": "michael@learnosity.com",
Expand Down Expand Up @@ -36,6 +36,7 @@
"collectCoverage": true
},
"dependencies": {
"entities": "^4.5.0",
"howler": "^2.2.4",
"mousetrap": "^1.6.5",
"platform-detect": "^3.0.1",
Expand Down
14 changes: 12 additions & 2 deletions src/assessment/extensions/validation/essayLimitByCharacter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as activity from '../../core/activity';
import * as player from '../../core/player';
import * as items from '../../core/items';
import * as questions from '../../core/questions';
import * as entities from 'entities';

/**
* Extensions add specific functionality to Items API.
Expand Down Expand Up @@ -263,11 +264,20 @@ function setQuestionListeners() {
* @ignore
*/
function checkLimit(questionInstance, setUI = true) {
const type = questionInstance.getQuestion().type;
const maxLength = questionInstance.getQuestion().max_length;
const rawResponse = questionInstance.getResponse()?.value ? questionInstance.getResponse()?.value : '';
const response = state.includeSpaces ? stripHtml(rawResponse) : stripSpaces(stripHtml(rawResponse));
const strLength = response.length;
let validLength = true;
let response;
let strLength;

if (type === 'plaintext') {
response = state.includeSpaces ? rawResponse : stripSpaces(rawResponse);
strLength = response.length;
} else {
response = state.includeSpaces ? stripHtml(rawResponse) : stripSpaces(stripHtml(rawResponse));
strLength = entities.decodeHTML(response).length;
}

if (maxLength) {
if (strLength > maxLength) {
Expand Down

0 comments on commit ed8c1aa

Please sign in to comment.