3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 11:12:42 +01:00

pbot-vm: fix invalid character encountered in JSON string

This commit is contained in:
Pragmatic Software 2022-04-04 21:41:27 -07:00
parent 4535881898
commit 757088987d
2 changed files with 9 additions and 1 deletions

View File

@ -29,6 +29,7 @@ no warnings qw(experimental::signatures);
use IPC::Open2; use IPC::Open2;
use JSON::XS; use JSON::XS;
use Data::Dumper; use Data::Dumper;
use Encode qw(decode encode);
# set debug flag from DEBUG env or here # set debug flag from DEBUG env or here
my $debug = $ENV{DEBUG} // 0; my $debug = $ENV{DEBUG} // 0;
@ -152,6 +153,13 @@ sub gdbmi_to_hash($text, $makejson = 1) {
# when and why the backslashes double up) # when and why the backslashes double up)
$text =~ s/\\+(\d{3})/$1 >= 0x20 ? chr oct $1 : "\\\\$1"/ge; $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 hashtable decoded from json
return decode_json("{$text}"); return decode_json("{$text}");
} }

View File

@ -25,7 +25,7 @@ use PBot::Imports;
# These are set by the /misc/update_version script # These are set by the /misc/update_version script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 4521, BUILD_REVISION => 4523,
BUILD_DATE => "2022-04-04", BUILD_DATE => "2022-04-04",
}; };