From 110912e85df8c55a786b5f0826f9812efbb3e055 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 4 Apr 2022 22:10:50 -0700 Subject: [PATCH] pbot-vm: use coderef to simplify escaping of malformed Unicode --- applets/pbot-vm/guest/bin/guest-gdb | 9 +-------- lib/PBot/VERSION.pm | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/applets/pbot-vm/guest/bin/guest-gdb b/applets/pbot-vm/guest/bin/guest-gdb index f0c87048..ff8337b6 100755 --- a/applets/pbot-vm/guest/bin/guest-gdb +++ b/applets/pbot-vm/guest/bin/guest-gdb @@ -154,14 +154,7 @@ sub gdbmi_to_hash($text, $makejson = 1) { $text =~ s/\\+(\d{3})/$1 >= 0x20 ? chr oct $1 : "\\\\$1"/ge; # escape malformed unicode - my $octets; - - while (1) { - $octets .= decode('UTF-8', $text, Encode::FB_QUIET); - last if not length $text; - $text =~ s/(.)/sprintf '\\\\x%X', ord $1/e; - } - + my $octets = decode('UTF-8', $text, sub { sprintf '\\\\x%X', shift }); $text = encode('UTF-8', $octets, Encode::FB_CROAK); # escape invalid JSON characters diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 2fc7c131..2f39064e 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 => 4524, + BUILD_REVISION => 4525, BUILD_DATE => "2022-04-04", };