mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-25 20:22:37 +01:00
Fix UTF-8 encoding
This commit is contained in:
parent
e908dd1640
commit
e736051de5
@ -77,13 +77,16 @@ sub execute {
|
||||
|
||||
$stdin //= '';
|
||||
|
||||
$stdin = encode('UTF-8', $stdin);
|
||||
@cmdline = map { encode('UTF-8', $_) } @cmdline;
|
||||
|
||||
print STDERR "execute ($timeout) [$stdin] @cmdline\n";
|
||||
|
||||
my ($exitval, $stdout, $stderr) = eval {
|
||||
my ($stdout, $stderr);
|
||||
run \@cmdline, \$stdin, \$stdout, \$stderr, timeout($timeout);
|
||||
my $exitval = $? >> 8;
|
||||
return ($exitval, $stdout, $stderr);
|
||||
return ($exitval, decode('UTF-8', $stdout), decode('UTF-8', $stderr));
|
||||
};
|
||||
|
||||
if (my $exception = $@) {
|
||||
|
@ -43,7 +43,7 @@ sub execute($command) {
|
||||
# to get $? from pipe
|
||||
local $SIG{CHLD} = 'DEFAULT';
|
||||
|
||||
my $pid = open(my $fh, '-|', split / /, $command);
|
||||
my $pid = open(my $fh, '-|', split / /, encode('UTF-8', $command));
|
||||
|
||||
if (not defined $pid) {
|
||||
print "Couldn't fork: $!\n";
|
||||
@ -55,7 +55,7 @@ sub execute($command) {
|
||||
local $SIG{ALRM} = sub { kill 9, $pid; die "Timed-out: $output\n"; };
|
||||
alarm(COMPILE_TIMEOUT);
|
||||
|
||||
while (my $line = <$fh>) {
|
||||
while (my $line = decode('UTF-8', <$fh>)) {
|
||||
$output .= $line;
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ sub handle_client($client, $heartbeat) {
|
||||
local $SIG{ALRM} = sub { die "Client I/O timed-out\n"; };
|
||||
alarm 5;
|
||||
|
||||
while (my $line = <$client>) {
|
||||
while (my $line = decode('UTF-8', <$client>)) {
|
||||
$line =~ s/[\r\n]+$//;
|
||||
next if $line =~ m/^\s*$/;
|
||||
|
||||
@ -214,7 +214,7 @@ sub handle_client($client, $heartbeat) {
|
||||
$timed_out = 1;
|
||||
}
|
||||
|
||||
print $client $result . "\n";
|
||||
print $client encode('UTF-8', $result . "\n");
|
||||
last;
|
||||
}
|
||||
};
|
||||
@ -238,6 +238,9 @@ sub handle_client($client, $heartbeat) {
|
||||
}
|
||||
|
||||
sub main() {
|
||||
binmode(STDOUT, ':utf8');
|
||||
binmode(STDERR, ':utf8');
|
||||
|
||||
# let OS clean-up child exits
|
||||
$SIG{CHLD} = 'IGNORE';
|
||||
|
||||
|
@ -210,7 +210,7 @@ sub execute {
|
||||
my $stdin = $self->{options}->{'-stdin'};
|
||||
|
||||
if (not length $stdin) {
|
||||
$stdin = `fortune -u -s`;
|
||||
$stdin = decode('UTF-8', `fortune -u -s`);
|
||||
$stdin =~ s/[\n\r\t]/ /msg;
|
||||
$stdin =~ s/:/ - /g;
|
||||
$stdin =~ s/\s+/ /g;
|
||||
@ -270,7 +270,7 @@ sub execute {
|
||||
$compile_in->{'persist-key'} = $self->{'persist-key'} if length $self->{'persist-key'};
|
||||
|
||||
my $compile_json = encode_json($compile_in);
|
||||
$compile_json .= encode('UTF-8', "\n:end:\n");
|
||||
$compile_json .= "\n:end:\n";
|
||||
|
||||
my $length = length $compile_json;
|
||||
my $sent = 0;
|
||||
|
1
applets/urban
vendored
1
applets/urban
vendored
@ -5,6 +5,7 @@
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use utf8;
|
||||
|
||||
use WebService::UrbanDictionary;
|
||||
use Getopt::Long qw(GetOptionsFromString);
|
||||
|
@ -78,10 +78,6 @@ sub launch_applet {
|
||||
my ($exitval, $stdout, $stderr) = eval {
|
||||
my $args = $context->{arguments};
|
||||
|
||||
if (not $context->{args_utf8}) {
|
||||
$args = encode('UTF-8', $args);
|
||||
}
|
||||
|
||||
my $strip_quotes = 1;
|
||||
|
||||
$strip_quotes = 0 if $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, 'keep-quotes');
|
||||
@ -92,12 +88,17 @@ sub launch_applet {
|
||||
|
||||
my ($stdin, $stdout, $stderr);
|
||||
|
||||
# encode as UTF-8 if not already encoded (e.g. by encode_json)
|
||||
if (not $context->{args_utf8}) {
|
||||
@cmdline = map { encode('UTF-8', $_) } @cmdline;
|
||||
}
|
||||
|
||||
run \@cmdline, \$stdin, \$stdout, \$stderr, timeout($timeout);
|
||||
|
||||
my $exitval = $? >> 8;
|
||||
|
||||
utf8::decode $stdout;
|
||||
utf8::decode $stderr;
|
||||
$stdout = decode('UTF-8', $stdout);
|
||||
$stderr = decode('UTF-8', $stderr);
|
||||
|
||||
return ($exitval, $stdout, $stderr);
|
||||
};
|
||||
|
@ -25,8 +25,8 @@ use PBot::Imports;
|
||||
# These are set by the /misc/update_version script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 4624,
|
||||
BUILD_DATE => "2023-02-24",
|
||||
BUILD_REVISION => 4626,
|
||||
BUILD_DATE => "2023-03-12",
|
||||
};
|
||||
|
||||
sub initialize {}
|
||||
|
Loading…
Reference in New Issue
Block a user