Merge pull request #5599 from edx/adam/fix-matlab-invalid-char
gracefully fail when parsing xml with non-compatible string (TNL-347)
This commit is contained in:
@@ -2111,7 +2111,13 @@ class CodeResponse(LoncapaResponse):
|
||||
except etree.XMLSyntaxError as _err:
|
||||
# If `html` contains attrs with no values, like `controls` in <audio controls src='smth'/>,
|
||||
# XML parser will raise exception, so wee fallback to html5parser, which will set empty "" values for such attrs.
|
||||
parsed = html5lib.parseFragment(msg, treebuilder='lxml', namespaceHTMLElements=False)
|
||||
try:
|
||||
parsed = html5lib.parseFragment(msg, treebuilder='lxml', namespaceHTMLElements=False)
|
||||
except ValueError:
|
||||
# the parsed message might contain strings that are not
|
||||
# xml compatible, in which case, throw the error message
|
||||
parsed = False
|
||||
|
||||
if not parsed:
|
||||
log.error("Unable to parse external grader message as valid"
|
||||
" XML: score_msg['msg']=%s", msg)
|
||||
|
||||
@@ -1006,6 +1006,7 @@ class CodeResponseTest(ResponseTest):
|
||||
|
||||
invalid_grader_msgs = [
|
||||
'<audio', # invalid XML and HTML5
|
||||
'<p>\b</p>', # invalid special character
|
||||
]
|
||||
|
||||
answer_ids = sorted(self.problem.get_question_answers())
|
||||
|
||||
Reference in New Issue
Block a user