diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 39c79f8f26..1d5386b566 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -834,7 +834,7 @@ class MatlabInput(CodeInput): 'audio': ['controls', 'autobuffer', 'autoplay', 'src'], 'img': ['src', 'width', 'height', 'class']}) self.queue_msg = bleach.clean(self.input_state['queue_msg'], - tags=bleach.ALLOWED_TAGS + ['div', 'p', 'audio', 'pre', 'img'], + tags=bleach.ALLOWED_TAGS + ['div', 'p', 'audio', 'pre', 'img', 'span'], styles=['white-space'], attributes=attributes ) diff --git a/common/lib/capa/capa/tests/test_inputtypes.py b/common/lib/capa/capa/tests/test_inputtypes.py index 81acd89afc..24ea807c19 100644 --- a/common/lib/capa/capa/tests/test_inputtypes.py +++ b/common/lib/capa/capa/tests/test_inputtypes.py @@ -601,7 +601,6 @@ class MatlabTest(unittest.TestCase): elt = etree.fromstring(self.xml) the_input = self.input_class(test_capa_system(), elt, state) - context = the_input._get_render_context() self.assertEqual(the_input.status, 'queued') @@ -612,7 +611,6 @@ class MatlabTest(unittest.TestCase): elt = etree.fromstring(self.xml) the_input = self.input_class(test_capa_system(), elt, state) - context = the_input._get_render_context() self.assertEqual(the_input.status, 'unsubmitted') self.assertEqual(the_input.msg, 'No response from Xqueue within {} seconds. Aborted.'.format(XQUEUE_TIMEOUT)) @@ -625,7 +623,6 @@ class MatlabTest(unittest.TestCase): elt = etree.fromstring(self.xml) the_input = self.input_class(test_capa_system(), elt, state) - context = the_input._get_render_context() self.assertEqual(the_input.status, 'unsubmitted') @@ -714,6 +711,35 @@ class MatlabTest(unittest.TestCase): received = fromstring(context['queue_msg']) html_tree_equal(received, expected) + def test_matlab_queue_message_allowed_tags(self): + """ + Test allowed tags. + """ + allowed_tags = ['div', 'p', 'audio', 'pre', 'span'] + for tag in allowed_tags: + queue_msg = "<{0}>Test message".format(tag) + state = { + 'input_state': {'queue_msg': queue_msg}, + 'status': 'queued', + } + elt = etree.fromstring(self.xml) + the_input = self.input_class(test_capa_system(), elt, state) + self.assertEqual(the_input.queue_msg, queue_msg) + + def test_matlab_queue_message_not_allowed_tag(self): + """ + Test not allowed tag. + """ + not_allowed_tag = 'script' + queue_msg = "<{0}>Test message".format(not_allowed_tag) + state = { + 'input_state': {'queue_msg': queue_msg}, + 'status': 'queued', + } + elt = etree.fromstring(self.xml) + the_input = self.input_class(test_capa_system(), elt, state) + expected = "<script>Test message</script>" + self.assertEqual(the_input.queue_msg, expected) def html_tree_equal(received, expected): """