From 3d311296eb90b9fae009341b7ac3787b9a545a68 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 7 Apr 2022 18:24:57 -0700 Subject: [PATCH] pbot-vm: output postprocessing: escape control characters/unprintable characters --- .../pbot-vm/host/lib/Languages/_default.pm | 23 ++++++++++++++++++- lib/PBot/VERSION.pm | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/applets/pbot-vm/host/lib/Languages/_default.pm b/applets/pbot-vm/host/lib/Languages/_default.pm index 2b78b0fe..a5fccb9f 100755 --- a/applets/pbot-vm/host/lib/Languages/_default.pm +++ b/applets/pbot-vm/host/lib/Languages/_default.pm @@ -360,9 +360,30 @@ sub postprocess_output($self) { } $self->{output} = $boutput; + # bell my @beeps = qw/*BEEP* *BING* *DING* *DONG* *CLUNK* *BONG* *PING* *BOOP* *BLIP* *BOP* *WHIRR*/; - $self->{output} =~ s/\007/$beeps[rand @beeps]/g; + + # known control characters + my %escapes = ( + "\e" => '', + "\f" => '', + + # \r and \n are disabled so the bot itself processes them, e.g. when + # web-pasting, etc. feel free to uncomment them if you like (add them + # to the group in the substitution regex as well). + + # "\r" => '', + # "\n" => '', + + # \t is left alone + ); + + $self->{output} =~ s/([\e\f])/$escapes{$1}/gs; + + # other unprintables + my %disregard = ( "\n" => 1, "\r" => 1, "\t" => 1 ); + $self->{output} =~ s/([\x00-\x1f])/$disregard{$1} ? $1 : sprintf('\x%X', ord $1)/gse; } sub show_output($self) { diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index f54d9b1d..9798f5d0 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,8 +25,8 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4528, - BUILD_DATE => "2022-04-06", + BUILD_REVISION => 4530, + BUILD_DATE => "2022-04-07", }; sub initialize {}