Resolve encoding problem found by attempting to register patrons with Unicode names
authordbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 22 Feb 2011 14:28:19 +0000 (14:28 +0000)
committerdbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 22 Feb 2011 14:28:19 +0000 (14:28 +0000)
Symptoms were:

1. a gateway.log entry showing http_translator receiving an XMPP error message
2. a corresponding osrfsys.log entry "server: died with error Wide character in syswrite at /usr/local/share/perl5/OpenSRF/Server.pm line 239"

Per normal Perl Unicode handling practices, decoding input and encoding output
using the Encode module and decode_utf8() / encode_utf8() appears to resolve
the problem.

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2168 9efc2488-bf62-4759-914b-345cdb29e865

src/perl/lib/OpenSRF/Server.pm

index 279c4a5..91763d9 100644 (file)
@@ -22,6 +22,7 @@ use OpenSRF::Transport::PeerHandle;
 use OpenSRF::Utils::SettingsClient;
 use OpenSRF::Utils::Logger qw($logger);
 use OpenSRF::Transport::SlimJabber::Client;
+use Encode;
 use POSIX qw/:sys_wait_h :errno_h/;
 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
 use IO::Select;
@@ -235,8 +236,8 @@ sub build_osrf_handle {
 # ----------------------------------------------------------------
 sub write_child {
     my($self, $child, $msg) = @_;
-    my $xml = $msg->to_xml;
-    syswrite($child->{pipe_to_child}, $xml);
+    my $xml = decode_utf8($msg->to_xml);
+    syswrite($child->{pipe_to_child}, encode_utf8($xml));
 }
 
 # ----------------------------------------------------------------