3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-01 17:16:39 +02:00

Fix incorrect truncation length when web-pasting content containing Unicode

This commit is contained in:
Pragmatic Software 2020-02-18 20:05:47 -08:00
parent 3c2a24781d
commit f13df2245a
2 changed files with 8 additions and 3 deletions

View File

@ -707,10 +707,16 @@ sub truncate_result {
my ($self, $from, $nick, $text, $original_result, $result, $paste) = @_;
my $max_msg_len = $self->{pbot}->{registry}->get_value('irc', 'max_msg_len');
utf8::encode $result;
utf8::encode $original_result;
use bytes;
if (length $result > $max_msg_len) {
my $link;
if ($paste) {
$original_result = substr $original_result, 0, 8000;
my $max_paste_len = $self->{pbot}->{registry}->get_value('paste', 'max_length') // 1024 * 32;
$original_result = substr $original_result, 0, $max_paste_len;
$link = $self->{pbot}->{webpaste}->paste("[" . (defined $from ? $from : "stdin") . "] <$nick> $text\n\n$original_result");
} else {
$link = 'undef';
@ -721,12 +727,12 @@ sub truncate_result {
else { $trunc .= "$link]"; }
$self->{pbot}->{logger}->log("Message truncated -- pasted to $link\n") if $paste;
my $trunc_len = length $result < $max_msg_len ? length $result : $max_msg_len;
$result = substr($result, 0, $trunc_len);
substr($result, $trunc_len - length $trunc) = $trunc;
}
utf8::decode $result;
return $result;
}

View File

@ -44,7 +44,6 @@ sub paste {
%opts = (%default_opts, %opts);
$text =~ s/(.{120})\s/$1\n/g unless $opts{no_split};
$text = encode('UTF-8', $text);
my $result;
for (my $tries = 3; $tries > 0; $tries--) {