diff options
| author | 2021-03-17 17:45:14 +0800 | |
|---|---|---|
| committer | 2021-03-17 17:45:14 +0800 | |
| commit | b76d0e5a636f28767e5d5acbf28c6ee464c7fbde (patch) | |
| tree | 07450a8fe40582bcdbef9538552dfb2f48d2d0e0 | |
| parent | Merge pull request #1468 from python-discord/bug/info/bot-xk/defcon-threshold... (diff) | |
| parent | Merge 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.py | 3 |
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) |