fix: don't revert to advanced editor if problem contains fields like url_name (#1421)

This commit is contained in:
Braden MacDonald
2024-10-22 11:53:22 -07:00
committed by GitHub
parent 21cbf80f23
commit 8c8d9119d4
4 changed files with 20 additions and 6 deletions

View File

@@ -3,7 +3,12 @@
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
import _ from 'lodash';
import { ProblemTypeKeys, RichTextProblems, settingsOlxAttributes } from '../../../data/constants/problem';
import {
ProblemTypeKeys,
RichTextProblems,
settingsOlxAttributes,
ignoredOlxAttributes,
} from '../../../data/constants/problem';
export const indexToLetterMap = [...Array(26)].map((val, i) => String.fromCharCode(i + 65));
@@ -663,9 +668,12 @@ export class OLXParser {
return {};
}
if (Object.keys(this.problem).some((key) => key.indexOf('@_') !== -1 && !settingsOlxAttributes.includes(key))) {
throw new Error('Misc Attributes associated with problem, opening in advanced editor');
}
Object.keys(this.problem).forEach((key) => {
if (key.indexOf('@_') !== -1 && !settingsOlxAttributes.includes(key) && !ignoredOlxAttributes.includes(key)) {
const plainKey = key.replace(/^@_/, '');
throw new Error(`Unrecognized attribute "${plainKey}" associated with problem, opening in advanced editor`);
}
});
const problemType = this.getProblemType();

View File

@@ -58,7 +58,7 @@ describe('OLXParser', () => {
labelDescriptionQuestionOlxParser.getParsedOLXData();
} catch (e) {
expect(e).toBeInstanceOf(Error);
expect(e.message).toBe('Misc Attributes associated with problem, opening in advanced editor');
expect(e.message).toBe('Unrecognized attribute "markdown" associated with problem, opening in advanced editor');
}
});
});

View File

@@ -2,7 +2,7 @@
// lint is disabled for this file due to strict spacing
export const checkboxesOLXWithFeedbackAndHintsOLX = {
rawOLX: `<problem>
rawOLX: `<problem url_name="this_should_be_ignored">
<choiceresponse>
<p>You can use this template as a guide to the simple editor markdown and OLX markup to use for checkboxes 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>

View File

@@ -233,3 +233,9 @@ export const settingsOlxAttributes = [
'@_submission_wait_seconds',
'@_attempts_before_showanswer_button',
] as const;
export const ignoredOlxAttributes = [
// '@_markdown', // Not sure if this is safe to ignore; some tests seem to indicate it's not.
'@_url_name',
'@_x-is-pointer-node',
] as const;