From ef5179790b43cdbbc54601d43dedec645c62d95d Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 24 Nov 2009 17:52:34 +0000 Subject: [PATCH] Patch from Josh Rosenbaum to fix encapsulation problems. (closes: CPAN#15210) --- AuthorizeNet/AIM.pm | 28 ++++++++++++++++++++++++++-- Changes | 5 ++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/AuthorizeNet/AIM.pm b/AuthorizeNet/AIM.pm index 5324e51..2906079 100644 --- a/AuthorizeNet/AIM.pm +++ b/AuthorizeNet/AIM.pm @@ -229,9 +229,33 @@ sub submit { $post_data{'x_Email_Customer'} = 'FALSE'; } + my $data_string = join("", values %post_data); + + my $encap_character; + # The first set of characters here are recommended by authorize.net in their + # encapsulating character example. + # The second set we made up hoping they will work if the first fail. + # The third chr(31) is the binary 'unit separator' and is our final last + # ditch effort to find something not in the input. + foreach my $char( qw( | " ' : ; / \ - * ), '#', qw( ^ + < > [ ] ~), chr(31) ){ + if( index($data_string, $char) == -1 ){ # found one. + $encap_character = $char; + last; + } + } + + if(!$encap_character){ + $self->is_success(0); + $self->error_message( + "DEBUG: Input contains all encapsulating characters." + . " Please remove | or ^ from your input if possible." + ); + return; + } + $post_data{'x_ADC_Delim_Data'} = 'TRUE'; $post_data{'x_delim_char'} = ','; - $post_data{'x_encap_char'} = '"'; + $post_data{'x_encap_char'} = $encap_character; $post_data{'x_ADC_URL'} = 'FALSE'; $post_data{'x_Version'} = '3.1'; @@ -247,7 +271,7 @@ sub submit { #trim 'ip_addr="1.2.3.4"' added by eProcessingNetwork Authorize.Net compat $page =~ s/,ip_addr="[\d\.]+"$//; - my $csv = new Text::CSV_XS({ binary=>1, escape_char=>'' }); + my $csv = new Text::CSV_XS({ binary=>1, escape_char=>'', quote_char => $encap_character }); $csv->parse($page); my @col = $csv->fields(); diff --git a/Changes b/Changes index a5b8266..eeb38dd 100644 --- a/Changes +++ b/Changes @@ -5,9 +5,12 @@ Revision history for Perl extension Business::OnlinePayment::AuthorizeNet. - Patch from Nate Nuss implementing ("Additional Shipping Information (Level 2 Data)" ~pg 24 in the AIM guide): tax, freight, duty, tax_exempt, po_number. Thanks! + (closes: CPAN#42046) - Patch from Michael Peters to fix a bug in email address handling: exclude x_Email_Customer flag when it is not specified in content, - to avoid overriding admin settings. + to avoid overriding admin settings. (closes: CPAN#51501) + - Patch from Josh Rosenbaum to fix encapsulation problems. Thanks! + (closes: CPAN#15210) 3.20 Wed Jun 18 16:46:10 PDT 2008 - Patch from Erik Hollensbe implementing -- 2.11.0