3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-07 03:49:04 +02:00

Fix some UTF8 <=> JSON encoding issues?

This commit is contained in:
Pragmatic Software 2017-11-30 18:46:14 -08:00
parent 8d560ef988
commit 7b142c68f5

View File

@ -374,6 +374,10 @@ sub find_factoid {
sub escape_json { sub escape_json {
my ($self, $text) = @_; my ($self, $text) = @_;
my $thing = {thing => $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; my $json = encode_json $thing;
$json =~ s/^{".*":"//; $json =~ s/^{".*":"//;
$json =~ s/"}$//; $json =~ s/"}$//;
@ -503,6 +507,12 @@ sub expand_action_arguments {
} else { } else {
%h = (args => $input); %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; my $jsonargs = encode_json \%h;
$jsonargs =~ s/^{".*":"//; $jsonargs =~ s/^{".*":"//;
$jsonargs =~ s/"}$//; $jsonargs =~ s/"}$//;