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:
Adam
2014-10-17 09:14:21 -04:00
2 changed files with 8 additions and 1 deletions

View File

@@ -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)

View File

@@ -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())