Skip to content

Commit

Permalink
fix: don't revert to advanced editor if problem contains fields like …
Browse files Browse the repository at this point in the history
…url_name (#1421)
  • Loading branch information
bradenmacdonald authored Oct 22, 2024
1 parent 21cbf80 commit 8c8d911
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/editors/containers/ProblemEditor/data/OLXParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions src/editors/data/constants/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 8c8d911

Please sign in to comment.