LP#1373690 Trigger EDI escaper
authorBill Erickson <berickxx@gmail.com>
Thu, 25 Sep 2014 02:23:24 +0000 (22:23 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 13 May 2015 22:41:36 +0000 (18:41 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.data.acq-order-edi.sql

index 7c9127a..70d3844 100644 (file)
@@ -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) = @_;
index 32b64e4..a9d65a0 100644 (file)
@@ -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'