Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions common/lib/xmodule/xmodule/capa_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,22 @@ def index_dictionary(self):
# Make optioninput's options index friendly by replacing the actual tag with the values
capa_content = re.sub(r'<optioninput options="\(([^"]+)\)".*?>\s*|\S*<\/optioninput>', r'\1', self.data)

# Removing solutions and hints, as well as script and style
# Remove the following tags with content that can leak hints or solutions:
# - `solution` (with optional attributes) and `solutionset`.
# - `targetedfeedback` (with optional attributes) and `targetedfeedbackset`.
# - `answer` (with optional attributes).
# - `script` (with optional attributes).
# - `style` (with optional attributes).
# - various types of hints (with optional attributes) and `hintpart`.
capa_content = re.sub(
re.compile(
r"""
<solution>.*?</solution> |
<script>.*?</script> |
<style>.*?</style> |
<[a-z]*hint.*?>.*?</[a-z]*hint>
<solution.*?>.*?</solution.*?> |
<targetedfeedback.*?>.*?</targetedfeedback.*?> |
<answer.*?>.*?</answer> |
<script.*?>.*?</script> |
<style.*?>.*?</style> |
<[a-z]*hint.*?>.*?</[a-z]*hint.*?>
""",
re.DOTALL |
re.VERBOSE),
Expand Down
47 changes: 27 additions & 20 deletions common/lib/xmodule/xmodule/tests/test_capa_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2562,25 +2562,32 @@ def test_response_types_multiple_tags(self):
def test_solutions_not_indexed(self):
xml = textwrap.dedent("""
<problem>
<solution>
<div class="detailed-solution">
<p>Explanation</p>

<p>This is what the 1st solution.</p>

</div>
</solution>

<solution>
<div class="detailed-solution">
<p>Explanation</p>

<p>This is the 2nd solution.</p>

</div>
</solution>


<solution>Test solution.</solution>
<solution explanation-id="solution0">Test solution with attribute.</solution>
<solutionset>
Test solutionset.
<solution explanation-id="solution1">Test solution within solutionset.</solution>
</solutionset>

<targetedfeedback>Test feedback.</targetedfeedback>
<targetedfeedback explanation-id="feedback0">Test feedback with attribute.</targetedfeedback>
<targetedfeedbackset>
Test FeedbackSet.
<targetedfeedback explanation-id="feedback1">Test feedback within feedbackset.</targetedfeedback>
</targetedfeedbackset>

<answer>Test answer.</answer>
<answer type="loncapa/python">Test answer with attribute.</answer>

<script>Test script.</script>
<script type="loncapa/python">Test script with attribute.</script>

<style>Test style.</style>
<style media="all and (max-width: 1920px)">Test style with attribute.</style>

<choicehint>Test choicehint.</choicehint>
<hint>Test hint.</hint>
<hintpart>Test hintpart.</hintpart>
</problem>
""")
name = "Blank Common Capa Problem"
Expand Down Expand Up @@ -2695,7 +2702,7 @@ def test_indexing_non_latin_problem(self):
""")
name = "Non latin Input"
descriptor = self._create_descriptor(sample_text_input_problem_xml, name=name)
capa_content = " FX1_VAL='Καλημέρα' Δοκιμή με μεταβλητές με Ελληνικούς χαρακτήρες μέσα σε python: $FX1_VAL "
capa_content = " Δοκιμή με μεταβλητές με Ελληνικούς χαρακτήρες μέσα σε python: $FX1_VAL "

descriptor_dict = descriptor.index_dictionary()
assert descriptor_dict['content']['capa_content'] == smart_str(capa_content)
Expand Down