From 3ada433527a078045870e77662576a2768052189 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 12 Mar 2023 18:28:50 -0700 Subject: [PATCH] Refactor UTF-8 fix --- applets/pbot-vm/host/lib/Languages/_default.pm | 10 +++------- lib/PBot/VERSION.pm | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/applets/pbot-vm/host/lib/Languages/_default.pm b/applets/pbot-vm/host/lib/Languages/_default.pm index c870d826..73ee6e45 100755 --- a/applets/pbot-vm/host/lib/Languages/_default.pm +++ b/applets/pbot-vm/host/lib/Languages/_default.pm @@ -309,18 +309,14 @@ sub execute { my $result = ""; my $got_result = 0; - while (my $line = decode('UTF-8', <$output>)) { + while (my $line = decode('UTF-8', <$output>, sub { sprintf '\\\\x%02X', shift })) { $line =~ s/[\r\n]+$//; last if $line =~ /^result:end$/; if ($line =~ /^result:/) { $line =~ s/^result://; - - $line = encode('UTF-8', $line); - my $octets = decode('UTF-8', $line, sub { sprintf '\\\\x%02X', shift }); - $line = encode('UTF-8', $octets, Encode::FB_CROAK); - - my $compile_out = decode_json($line); + # use JSON::XS->new->decode() for non-utf8 decoding + my $compile_out = JSON::XS->new->decode($line); $result .= "$compile_out->{result}\n"; $got_result = 1; next; diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 401562d7..62dc91b5 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 => 4628, + BUILD_REVISION => 4629, BUILD_DATE => "2023-03-12", };