mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
Fix incorrect truncation length when web-pasting content containing Unicode
This commit is contained in:
parent
3c2a24781d
commit
f13df2245a
@ -707,10 +707,16 @@ sub truncate_result {
|
|||||||
my ($self, $from, $nick, $text, $original_result, $result, $paste) = @_;
|
my ($self, $from, $nick, $text, $original_result, $result, $paste) = @_;
|
||||||
my $max_msg_len = $self->{pbot}->{registry}->get_value('irc', 'max_msg_len');
|
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) {
|
if (length $result > $max_msg_len) {
|
||||||
my $link;
|
my $link;
|
||||||
if ($paste) {
|
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");
|
$link = $self->{pbot}->{webpaste}->paste("[" . (defined $from ? $from : "stdin") . "] <$nick> $text\n\n$original_result");
|
||||||
} else {
|
} else {
|
||||||
$link = 'undef';
|
$link = 'undef';
|
||||||
@ -721,12 +727,12 @@ sub truncate_result {
|
|||||||
else { $trunc .= "$link]"; }
|
else { $trunc .= "$link]"; }
|
||||||
|
|
||||||
$self->{pbot}->{logger}->log("Message truncated -- pasted to $link\n") if $paste;
|
$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;
|
my $trunc_len = length $result < $max_msg_len ? length $result : $max_msg_len;
|
||||||
$result = substr($result, 0, $trunc_len);
|
$result = substr($result, 0, $trunc_len);
|
||||||
substr($result, $trunc_len - length $trunc) = $trunc;
|
substr($result, $trunc_len - length $trunc) = $trunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utf8::decode $result;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ sub paste {
|
|||||||
%opts = (%default_opts, %opts);
|
%opts = (%default_opts, %opts);
|
||||||
|
|
||||||
$text =~ s/(.{120})\s/$1\n/g unless $opts{no_split};
|
$text =~ s/(.{120})\s/$1\n/g unless $opts{no_split};
|
||||||
$text = encode('UTF-8', $text);
|
|
||||||
|
|
||||||
my $result;
|
my $result;
|
||||||
for (my $tries = 3; $tries > 0; $tries--) {
|
for (my $tries = 3; $tries > 0; $tries--) {
|
||||||
|
Loading…
Reference in New Issue
Block a user