about summary refs log tree commit homepage
path: root/lib/PublicInbox/NNTP.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-05-13 12:12:41 +0000
committerEric Wong <e@80x24.org>2016-05-13 12:12:41 +0000
commit821dcde53cc4ea636078b282c1d81a30f7070a96 (patch)
tree2cd67e7ddad56415c8f622e753dd72a280cab68d /lib/PublicInbox/NNTP.pm
parent265e79ff82ce6e22f039031f53068e51c6cc6c77 (diff)
downloadpublic-inbox-821dcde53cc4ea636078b282c1d81a30f7070a96.tar.gz
We need Perl to believe everything we send is UTF-8,
make it so, even if it may not be.

Fixes: 265e79ff82ce 'Revert "nntp: proper UTF-8 support (hopefully?)"'
Diffstat (limited to 'lib/PublicInbox/NNTP.pm')
-rw-r--r--lib/PublicInbox/NNTP.pm4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index d177bdc4..a6321489 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -16,6 +16,8 @@ use Data::Dumper qw(Dumper);
 use POSIX qw(strftime);
 use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
 use URI::Escape qw(uri_escape_utf8);
+use Encode qw(find_encoding);
+my $enc_utf8 = find_encoding('UTF-8');
 use constant {
         r501 => '501 command syntax error',
         r221 => '221 Header follows',
@@ -900,6 +902,7 @@ sub cmd_xpath ($$) {
 
 sub res ($$) {
         my ($self, $line) = @_;
+        $line = $enc_utf8->encode($line);
         do_write($self, $line . "\r\n");
 }
 
@@ -934,6 +937,7 @@ use constant MSG_MORE => ($^O eq 'linux') ? 0x8000 : 0;
 
 sub do_more ($$) {
         my ($self, $data) = @_;
+        $data = $enc_utf8->encode($data);
         if (MSG_MORE && !$self->{write_buf_size}) {
                 my $n = send($self->{sock}, $data, MSG_MORE);
                 if (defined $n) {