aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Kieran Siek <[email protected]>2021-03-17 17:45:14 +0800
committerGravatar GitHub <[email protected]>2021-03-17 17:45:14 +0800
commitb76d0e5a636f28767e5d5acbf28c6ee464c7fbde (patch)
tree07450a8fe40582bcdbef9538552dfb2f48d2d0e0
parentMerge pull request #1468 from python-discord/bug/info/bot-xk/defcon-threshold... (diff)
parentMerge branch 'main' into bug/info/bot-xr/code-block-null-byte (diff)
Merge pull request #1467 from python-discord/bug/info/bot-xr/code-block-null-byte
Code block: remove null bytes before parsing AST
-rw-r--r--bot/exts/info/codeblock/_parsing.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/bot/exts/info/codeblock/_parsing.py b/bot/exts/info/codeblock/_parsing.py
index e35fbca22..73fd11b94 100644
--- a/bot/exts/info/codeblock/_parsing.py
+++ b/bot/exts/info/codeblock/_parsing.py
@@ -103,6 +103,9 @@ def _is_python_code(content: str) -> bool:
"""Return True if `content` is valid Python consisting of more than just expressions."""
log.trace("Checking if content is Python code.")
try:
+ # Remove null bytes because they cause ast.parse to raise a ValueError.
+ content = content.replace("\x00", "")
+
# Attempt to parse the message into an AST node.
# Invalid Python code will raise a SyntaxError.
tree = ast.parse(content)