fix: don't revert to advanced editor if problem contains fields like url_name (#1421)
This commit is contained in:
@@ -3,7 +3,12 @@
|
|||||||
|
|
||||||
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
|
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
|
||||||
import _ from 'lodash';
|
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));
|
export const indexToLetterMap = [...Array(26)].map((val, i) => String.fromCharCode(i + 65));
|
||||||
|
|
||||||
@@ -663,9 +668,12 @@ export class OLXParser {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(this.problem).some((key) => key.indexOf('@_') !== -1 && !settingsOlxAttributes.includes(key))) {
|
Object.keys(this.problem).forEach((key) => {
|
||||||
throw new Error('Misc Attributes associated with problem, opening in advanced editor');
|
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();
|
const problemType = this.getProblemType();
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ describe('OLXParser', () => {
|
|||||||
labelDescriptionQuestionOlxParser.getParsedOLXData();
|
labelDescriptionQuestionOlxParser.getParsedOLXData();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).toBeInstanceOf(Error);
|
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');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// lint is disabled for this file due to strict spacing
|
// lint is disabled for this file due to strict spacing
|
||||||
|
|
||||||
export const checkboxesOLXWithFeedbackAndHintsOLX = {
|
export const checkboxesOLXWithFeedbackAndHintsOLX = {
|
||||||
rawOLX: `<problem>
|
rawOLX: `<problem url_name="this_should_be_ignored">
|
||||||
<choiceresponse>
|
<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>
|
<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>
|
<label>Add the question text, or prompt, here. This text is required.</label>
|
||||||
|
|||||||
@@ -233,3 +233,9 @@ export const settingsOlxAttributes = [
|
|||||||
'@_submission_wait_seconds',
|
'@_submission_wait_seconds',
|
||||||
'@_attempts_before_showanswer_button',
|
'@_attempts_before_showanswer_button',
|
||||||
] as const;
|
] 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user