aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-10-14 18:53:48 -0700
committerGravatar MarkKoz <[email protected]>2020-10-14 18:53:48 -0700
commitd277ac6d3444bed43f921ee95f79255033e367ba (patch)
treefdcc7788fd82cd412ced8e32f1953e840cb8b8fe
parentMerge pull request #886 from python-discord/bug/utility/829/non-py-code-detec... (diff)
Code block: fix _fix_indentation failing for line counts of 1
This could be reproduced by editing a tracked message to a single line of invalid Python that lacks any back ticks. The code was assuming there would be multiple lines because that's what the default value for the threshold is, but this threshold is not applied to edited messages. Fixes BOT-A5
-rw-r--r--bot/exts/info/codeblock/_parsing.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/bot/exts/info/codeblock/_parsing.py b/bot/exts/info/codeblock/_parsing.py
index e67224494..a98218dfb 100644
--- a/bot/exts/info/codeblock/_parsing.py
+++ b/bot/exts/info/codeblock/_parsing.py
@@ -208,6 +208,10 @@ def _fix_indentation(content: str) -> str:
first_indent = _get_leading_spaces(content)
first_line = lines[0][first_indent:]
+ # Can't assume there'll be multiple lines cause line counts of edited messages aren't checked.
+ if len(lines) == 1:
+ return first_line
+
second_indent = _get_leading_spaces(lines[1])
# If the first line ends with a colon, all successive lines need to be indented one