From 757088987d0461d6f923e0c51a729d0183bead4f Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 4 Apr 2022 21:41:27 -0700 Subject: [PATCH] pbot-vm: fix invalid character encountered in JSON string --- applets/pbot-vm/guest/bin/guest-gdb | 8 ++++++++ lib/PBot/VERSION.pm | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/applets/pbot-vm/guest/bin/guest-gdb b/applets/pbot-vm/guest/bin/guest-gdb index a3ae00fc..5b9584b6 100755 --- a/applets/pbot-vm/guest/bin/guest-gdb +++ b/applets/pbot-vm/guest/bin/guest-gdb @@ -29,6 +29,7 @@ no warnings qw(experimental::signatures); use IPC::Open2; use JSON::XS; use Data::Dumper; +use Encode qw(decode encode); # set debug flag from DEBUG env or here my $debug = $ENV{DEBUG} // 0; @@ -152,6 +153,13 @@ sub gdbmi_to_hash($text, $makejson = 1) { # when and why the backslashes double up) $text =~ s/\\+(\d{3})/$1 >= 0x20 ? chr oct $1 : "\\\\$1"/ge; + # fix unicode + my $octets = decode('UTF-8', $text, Encode::FB_DEFAULT); + $text = encode('UTF-8', $octets, Encode::FB_CROAK); + + # escape invalid JSON characters + $text =~ s/([\x10-\x1f])/sprintf '\\\\x{%x}', ord $1/ge; + # return hashtable decoded from json return decode_json("{$text}"); } diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 04fb2fe7..d4d3f229 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,7 +25,7 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4521, + BUILD_REVISION => 4523, BUILD_DATE => "2022-04-04", };