From 9d2c3794a4c95f6c63a7de64172bc35a68403a4c Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Fri, 26 Feb 2021 14:21:00 +0100 Subject: Use base64 encoded code snippets --- backend/routes/forms/unittesting.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'backend/routes/forms') diff --git a/backend/routes/forms/unittesting.py b/backend/routes/forms/unittesting.py index 175701f..b12cff2 100644 --- a/backend/routes/forms/unittesting.py +++ b/backend/routes/forms/unittesting.py @@ -1,3 +1,4 @@ +import base64 from collections import namedtuple from itertools import count from textwrap import indent @@ -45,10 +46,9 @@ def _make_unit_code(units: dict[str, str]) -> str: def _make_user_code(code: str) -> str: - """Compose the user code into an actual string variable.""" - # Make sure that we we escape triple quotes in the user code - code = code.replace('"""', '\\"""') - return f'USER_CODE = r"""{code}"""' + """Compose the user code into an actual base64-encoded string variable.""" + code = base64.b64encode(code.encode("utf8")).decode("utf8") + return f'USER_CODE = b"{code}"' async def _post_eval(code: str) -> dict[str, str]: -- cgit v1.2.3