aboutsummaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-02-26 14:21:00 +0100
committerGravatar Matteo Bertucci <[email protected]>2021-02-26 14:21:00 +0100
commit9d2c3794a4c95f6c63a7de64172bc35a68403a4c (patch)
treec01d39e6f5862a00fc478da5f08d73ede43972dd /backend
parentProperly hadnle hidden tests starting with test_ (diff)
Use base64 encoded code snippets
Diffstat (limited to 'backend')
-rw-r--r--backend/routes/forms/unittesting.py8
1 files changed, 4 insertions, 4 deletions
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]: