Skip to content

Commit

Permalink
Prevent 3.13's ANSI escapes from mangling pinwand uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
thurisatic committed Nov 14, 2024
1 parent dcb1890 commit 15235ea
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bot/exts/utils/snekbox/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

log = get_logger(__name__)

ANSI_REGEX = re.compile(r"\N{ESC}\[[0-9;:]*m")
ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}")

# The timeit command should only output the very last line, so all other output should be suppressed.
Expand Down Expand Up @@ -281,7 +282,10 @@ async def format_output(
output = f"{output[:max_chars]}\n... (truncated - too long)"

if truncated:
paste_link = await self.upload_output(original_output)
# ANSI colors are quite nice, but don't render in pinwand,
# thus mangling the output
ansiless_output = ANSI_REGEX.sub("", original_output)
paste_link = await self.upload_output(ansiless_output)

if output_default and not output:
output = output_default
Expand Down

0 comments on commit 15235ea

Please sign in to comment.