From 13bad8097a693995089e08c9bc4352445dec1929 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Tue, 11 Oct 2011 11:25:51 -0400 Subject: [PATCH] More filtering of characters that could end up in PO JEDI template output Backslashes cause problems too. Let's JSON encode this thing and get it right once and for all. Signed-off-by: Lebbeous Fogle-Weekley Signed-off-by: Ben Shum Signed-off-by: Bill Erickson --- .../OpenILS/Application/Trigger/Reactor.pm | 27 ++++++++++++++++--- Open-ILS/src/support-scripts/edi_pusher.pl | 8 +----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm index 5f0797226c..14a69e7b31 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm @@ -8,6 +8,7 @@ use Unicode::Normalize; use XML::LibXML; use OpenSRF::Utils qw/:datetime/; use OpenSRF::Utils::Logger qw(:logger); +use OpenSRF::Utils::JSON; use OpenILS::Application::AppUtils; use OpenILS::Utils::CStoreEditor qw/:funcs/; my $U = 'OpenILS::Application::AppUtils'; @@ -154,6 +155,16 @@ my $_TT_helpers = { get_li_attr => \&get_li_attr, get_li_attr_jedi => sub { + # This helper has to mangle data in at least three interesting ways. + # + # 1) We'll be receiving data that may already have some \-escaped + # characters. + # + # 2) We need our output to be valid JSON. + # + # 3) We need our output to yield valid and unproblematic EDI when + # passed through edi4r by the edi_pusher.pl script. + my $value = get_li_attr(@_); if ($value) { # Here we can add any number of special case transformations to @@ -165,14 +176,24 @@ my $_TT_helpers = { chop $value; } - # Make sure any double quotation marks are escaped. - $value =~ s/"/\\"/g; + # Typical vendors dealing with EDIFACT would seem not to want + # any unicode characters, so trash them. Yes, they're already + # in the data escaped like this at this point even though we + # haven't JSON-escaped things yet. + $value =~ s/\\u[0-9a-f]{4}//g; # What the heck, get rid of [ ] too (although I couldn't get them - # to cause any problems for me. + # to cause any problems for me, problems have been reported. See + # LP #812593). $value =~ s/[\[\]]//g; } + $value = OpenSRF::Utils::JSON->perl2JSON($value); + + # Existing action/trigger templates expect an unquoted string. + $value =~ s/^"//g; + chop $value; + return $value; }, diff --git a/Open-ILS/src/support-scripts/edi_pusher.pl b/Open-ILS/src/support-scripts/edi_pusher.pl index ea9d63e1d8..80e4e19ad1 100755 --- a/Open-ILS/src/support-scripts/edi_pusher.pl +++ b/Open-ILS/src/support-scripts/edi_pusher.pl @@ -155,13 +155,7 @@ foreach my $def (@$defs) { printf STDERR "ERROR: No edi_default account found for $logstr. File will not be sent!\n"; } - my $jedi = $event->template_output()->data; - - # Crucial identifiers won't contain unicode characters, and EDIFACT - # (or at least our translator) generally can't handle them anyway. - $jedi =~ s/\\u[0-9a-f]{4}//g; - - $message->jedi($jedi); + $message->jedi($event->template_output()->data); print "\ntarget->provider->edi_default->id: ", $target->provider->edi_default->id, "\n"; my $logstr2 = sprintf "event %s, PO %s, template_output %s", $_->{id}, $message->purchase_order, $event->template_output->id; -- 2.43.2