From e03376e512ca820c8de16f9bd18fb21076913645 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 24 Sep 2014 22:23:24 -0400 Subject: [PATCH] LP#1373690 Trigger EDI escaper Signed-off-by: Bill Erickson --- .../lib/OpenILS/Application/Trigger/Reactor.pm | 37 ++++++++++++++++++++++ .../src/sql/Pg/upgrade/XXXX.data.acq-order-edi.sql | 8 ++--- 2 files changed, 41 insertions(+), 4 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 7c9127aa0f..70d3844b26 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm @@ -291,6 +291,43 @@ $_TT_helpers = { return $value; }, + get_li_attr_edi => sub { + my $value = get_li_attr(@_); + return $_TT_helpers->{escape_edi}->($value); + }, + + + # Removes potentially troublesome characters from text for inclusion + # in an EDI document. + # See also get_li_attr_jedi() + escape_edi => sub { + my $value = shift; + { + no warnings 'uninitialized'; + $value .= ""; # force to string + }; + + # Typical vendors dealing with EDIFACT (or is the problem with + # our EDI translator itself?) would seem not to want + # any characters outside the ASCII range, so trash them. + $value =~ s/[^[:ascii:]]//g; + + # What the heck, get rid of [ ] too (although I couldn't get them + # to cause any problems for me, problems have been reported. See + # LP #812593). + $value =~ s/[\[\]]//g; + + # The ? character, if in the final position of a string, breaks + # the translator. + or ' or : could be problematic, too. And we must + # avoid leaving a hanging \. + while ($value =~ /[\\\?\+':]$/) { + chop $value; + } + + return $value; + }, + + get_queued_bib_attr => sub { my $name = shift or return; # the first arg is always the name my ($attr) = @_; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.acq-order-edi.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.acq-order-edi.sql index 32b64e4bca..a9d65a08b6 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.acq-order-edi.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.acq-order-edi.sql @@ -101,10 +101,10 @@ CUX+2:USD:9' END -%] LIN+[% li.id %]++[% idval %]:[% idqual %]' PIA+5+[% idval %]:[% idqual %]' -IMD+F+BTI+:::[% helpers.get_li_attr_jedi('title', '', li.attributes) %]' -IMD+F+BPU+:::[% helpers.get_li_attr_jedi('author', '', li.attributes) %]' -IMD+F+BPD+:::[% helpers.get_li_attr_jedi('pubdate', '', li.attributes) %]' -IMD+F+BPH+:::[% helpers.get_li_attr_jedi('pagination', '', li.attributes) %]' +IMD+F+BTI+:::[% helpers.get_li_attr_edi('title', '', li.attributes) %]' +IMD+F+BPU+:::[% helpers.get_li_attr_edi('author', '', li.attributes) %]' +IMD+F+BPD+:::[% helpers.get_li_attr_edi('pubdate', '', li.attributes) %]' +IMD+F+BPH+:::[% helpers.get_li_attr_edi('pagination','', li.attributes) %]' QTY+21:[% li.lineitem_details.size %]' FTX+LIN+1' PRI+AAB:30' -- 2.11.0