Fix grading parse.

This commit is contained in:
Cristiano Ferreira
2023-08-31 09:55:04 +01:00
parent ca6094c3e7
commit a31489d850
3 changed files with 1228 additions and 7 deletions

View File

@@ -23,7 +23,7 @@ def process_response(input_string, quotation_check_field):
index = input_string.index('{')
# Extract everything after the first '{' (inclusive)
result = input_string[index:]
if re.search(r"'" + quotation_check_field + "':\s*'(.*?)'", result):
if re.search(r"'" + quotation_check_field + "':\s*'(.*?)'", result, re.DOTALL | re.MULTILINE):
parsed_string = result.replace("\"", "\\\"")
pattern = r"(?<!\w)'|'(?!\w)"
parsed_string = re.sub(pattern, '"', parsed_string)
@@ -35,8 +35,8 @@ def process_response(input_string, quotation_check_field):
else:
json_obj = json.loads(result)
return json_obj
except json.JSONDecodeError:
print("Invalid JSON string!")
except Exception as e:
print(f"Invalid JSON string! Exception: {e}")
else:
return input_string