aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Bast <[email protected]>2021-04-08 14:31:26 -0700
committerGravatar Bast <[email protected]>2021-04-08 14:31:26 -0700
commitcf1cb44582ac165acf3113587a9ead2e4f964c26 (patch)
treeae8d0ab40ad56b66aa71d2f751482803cf9d3a9a
parentUse PYTHONIOENCODING to enable utf-8 stdout for the nsjail pipe, and handle t... (diff)
Match new unicode eval tests and output to the format and functions of others
-rw-r--r--snekbox/nsjail.py2
-rw-r--r--tests/test_nsjail.py20
2 files changed, 9 insertions, 13 deletions
diff --git a/snekbox/nsjail.py b/snekbox/nsjail.py
index a182406..9367cb2 100644
--- a/snekbox/nsjail.py
+++ b/snekbox/nsjail.py
@@ -214,7 +214,7 @@ class NsJail:
return CompletedProcess(
args,
None,
- "UnicodeDecodeError: invalid unicode in output pipe",
+ "UnicodeDecodeError: invalid Unicode in output pipe",
None,
)
diff --git a/tests/test_nsjail.py b/tests/test_nsjail.py
index cab9344..46193b2 100644
--- a/tests/test_nsjail.py
+++ b/tests/test_nsjail.py
@@ -103,22 +103,18 @@ class NsJailTests(unittest.TestCase):
def test_print_bad_unicode_encode_error(self):
result = self.nsjail.python3("print(chr(56550))")
self.assertEqual(result.returncode, 1)
- unicode_traceback = (
- "Traceback (most recent call last):\n"
- ' File "<string>", line 1, in <module>\n'
- "UnicodeEncodeError: 'utf-8' codec can't encode character '\\udce6'"
- " in position 0: surrogates not allowed\n"
- )
- self.assertEqual(result.stdout, unicode_traceback)
+ self.assertIn("UnicodeEncodeError", result.stdout)
self.assertEqual(result.stderr, None)
def test_unicode_env_erase_escape_fails(self):
- result = self.nsjail.python3(
- "import os, sys\nos.unsetenv('PYTHONIOENCODING')\n"
- "os.execl(sys.executable, 'python', '-c', 'print(chr(56550))')"
- )
+ result = self.nsjail.python3(dedent("""
+ import os
+ import sys
+ os.unsetenv('PYTHONIOENCODING')
+ os.execl(sys.executable, 'python', '-c', 'print(chr(56550))')
+ """).strip())
self.assertEqual(result.returncode, None)
- self.assertEqual(result.stdout, "UnicodeDecodeError: invalid unicode in output pipe")
+ self.assertEqual(result.stdout, "UnicodeDecodeError: invalid Unicode in output pipe")
self.assertEqual(result.stderr, None)
@unittest.mock.patch("snekbox.nsjail.DEBUG", new=False)