From 7b142c68f5fa30805122e0f2ddfa8744a90fd99e Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 30 Nov 2017 18:46:14 -0800 Subject: [PATCH] Fix some UTF8 <=> JSON encoding issues? --- PBot/Factoids.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index 29867b6b..36319217 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -374,6 +374,10 @@ sub find_factoid { sub escape_json { my ($self, $text) = @_; my $thing = {thing => $text}; + # not sure why we need this here, but it seems to stop strange + # text encoding issues in the following encode_json call + use Encode; + $thing->{thing} = decode('utf8', $thing->{thing}); my $json = encode_json $thing; $json =~ s/^{".*":"//; $json =~ s/"}$//; @@ -503,6 +507,12 @@ sub expand_action_arguments { } else { %h = (args => $input); } + + # not sure why we need this here, but it seems to stop strange + # text encoding issues in the following encode_json call + use Encode; + $h{args} = decode('utf8', $h{args}); + my $jsonargs = encode_json \%h; $jsonargs =~ s/^{".*":"//; $jsonargs =~ s/"}$//;