feat: add catch for script tags in question (#292)
This commit is contained in:
@@ -323,6 +323,9 @@ export class OLXParser {
|
||||
problemArray.forEach(tag => {
|
||||
const tagName = Object.keys(tag)[0];
|
||||
if (!nonQuestionKeys.includes(tagName)) {
|
||||
if (tagName === 'script') {
|
||||
throw new Error('Script Tag, reverting to Advanced Editor');
|
||||
}
|
||||
questionArray.push(tag);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
blankQuestionOLX,
|
||||
styledQuestionOLX,
|
||||
shuffleProblemOLX,
|
||||
scriptProblemOlX,
|
||||
} from './mockData/olxTestData';
|
||||
import { ProblemTypeKeys } from '../../../data/constants/problem';
|
||||
|
||||
@@ -181,6 +182,10 @@ describe('Check OLXParser for question parsing', () => {
|
||||
const question = olxparser.parseQuestions('numericalresponse');
|
||||
expect(question).toEqual(numericInputWithFeedbackAndHintsOLX.question);
|
||||
});
|
||||
test('Test Advanced Problem Type by script tag', () => {
|
||||
const olxparser = new OLXParser(scriptProblemOlX.rawOLX);
|
||||
expect(() => olxparser.parseQuestions('numericalresponse')).toThrow(new Error('Script Tag, reverting to Advanced Editor'));
|
||||
});
|
||||
test('Test OLX with no question content should have empty string for question', () => {
|
||||
const olxparser = new OLXParser(blankQuestionOLX.rawOLX);
|
||||
const problemType = olxparser.getProblemType();
|
||||
|
||||
@@ -551,6 +551,22 @@ export const advancedProblemOlX = {
|
||||
</formularesponse>
|
||||
</problem>`,
|
||||
};
|
||||
export const scriptProblemOlX = {
|
||||
rawOLX: `<problem>
|
||||
<script>
|
||||
some code
|
||||
</script>
|
||||
<numericalresponse answer="100">
|
||||
<p>You can use this template as a guide to the simple editor markdown and OLX markup to use for numerical input with hints and feedback problems. Edit this component to replace this template with your own assessment.</p>
|
||||
<label>Add the question text, or prompt, here. This text is required.</label>
|
||||
<description>You can add an optional tip or note related to the prompt like this. </description>
|
||||
<responseparam type="tolerance" default="5"/>
|
||||
<formulaequationinput/>
|
||||
<correcthint><p>You can specify optional feedback like this, which appears after this answer is submitted.</p></correcthint>
|
||||
<additional_answer answer="200"><correcthint><p>You can specify optional feedback like this, which appears after this answer is submitted.</p></correcthint></additional_answer>
|
||||
</numericalresponse>
|
||||
</problem>`,
|
||||
};
|
||||
export const multipleProblemOlX = {
|
||||
rawOLX: `<problem>
|
||||
<stringresponse answer="correct answer">
|
||||
|
||||
Reference in New Issue
Block a user