From 16e9dc2cd782f5b0ad16240163ae73e05a6f05b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Thu, 21 Sep 2017 14:13:33 +0200 Subject: [PATCH] Revert "_replace_special_chars in Helper ausgelagert." MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Funktion in die falsche Stelle ausgelagert, ferner zu 'speziell' um die für andere Anforderungen wiederzuverwerten This reverts commit fec48603264c8adad06fbc212358633778322b56. --- SL/DB/Helper/ReplaceSpecialChars.pm | 82 ----------------------------- SL/SEPA/XML.pm | 28 +++++++++- SL/SEPA/XML/Transaction.pm | 4 +- t/bank/bank_transactions.t | 13 +---- 4 files changed, 29 insertions(+), 98 deletions(-) delete mode 100644 SL/DB/Helper/ReplaceSpecialChars.pm diff --git a/SL/DB/Helper/ReplaceSpecialChars.pm b/SL/DB/Helper/ReplaceSpecialChars.pm deleted file mode 100644 index cbc677f3a..000000000 --- a/SL/DB/Helper/ReplaceSpecialChars.pm +++ /dev/null @@ -1,82 +0,0 @@ -package SL::DB::Helper::ReplaceSpecialChars; - -use strict; -use utf8; - -use parent qw(Exporter); -our @EXPORT = qw(replace_special_chars); - -use Carp; -use Text::Unidecode qw(unidecode); - - - - -sub replace_special_chars { - my $text = shift; - - return unless $text; - - my %special_chars = ( - 'ä' => 'ae', - 'ö' => 'oe', - 'ü' => 'ue', - 'Ä' => 'Ae', - 'Ö' => 'Oe', - 'Ü' => 'Ue', - 'ß' => 'ss', - '&' => '+', - '`' => '\'', - ); - - map { $text =~ s/$_/$special_chars{$_}/g; } keys %special_chars; - - # for all other non ascii chars 'OLÉ S.L.' and 'Årdberg AB'! - $text = unidecode($text); - - return $text; -} - -1; -__END__ - -=pod - -=encoding utf8 - -=head1 NAME - -SL::DB::Helper::ReplaceSpecialChars - Helper functions for replacing non-ascii characaters - -=head1 SYNOPSIS - - use SL::DB::Helper::ReplaceSpecialChars qw(replace_special_chars); - my $ansi_string = replace_special_chars("Überhaupt, with Olé \x{5317}\x{4EB0}"); # hint perldoc may already convert - print $ansi_string; - # Ueberhaupt, with Ole Bei Jing - -=head1 FUNCTIONS - -=over 4 - -=item C - -Given a text string this method replaces the most common german umlaute, -transforms '&' to '+' and escapes a single quote ('). -If there are still some non-ascii chars, we use unidecode to guess -a sensible ascii presentation, C - -=back - -=head1 BUGS - -Nothing here yet. - -=head1 AUTHOR - -M.Bunkus -J.Büren (Unidecode added) - -=cut - - diff --git a/SL/SEPA/XML.pm b/SL/SEPA/XML.pm index 54df4eda6..e4bf360d6 100644 --- a/SL/SEPA/XML.pm +++ b/SL/SEPA/XML.pm @@ -12,7 +12,6 @@ use XML::Writer; use SL::Iconv; use SL::SEPA::XML::Transaction; -use SL::DB::Helper::ReplaceSpecialChars qw(replace_special_chars); sub new { my $class = shift; @@ -41,7 +40,7 @@ sub _init { croak "Missing parameter: $missing_parameter" if ($missing_parameter); croak "Missing parameter: creditor_id" if !$self->{creditor_id} && $self->{collection}; - map { $self->{$_} = replace_special_chars($self->{iconv}->convert($self->{$_})) } qw(company message_id creditor_id); + map { $self->{$_} = $self->_replace_special_chars($self->{iconv}->convert($self->{$_})) } qw(company message_id creditor_id); } sub add_transaction { @@ -55,6 +54,31 @@ sub add_transaction { return 1; } +sub _replace_special_chars { + my $self = shift; + my $text = shift; + + my %special_chars = ( + 'ä' => 'ae', + 'ö' => 'oe', + 'ü' => 'ue', + 'Ä' => 'Ae', + 'Ö' => 'Oe', + 'Ü' => 'Ue', + 'ß' => 'ss', + '&' => '+', + '`' => '\'', + ); + + map { $text =~ s/$_/$special_chars{$_}/g; } keys %special_chars; + + # for all other non ascii chars 'OLÉ S.L.' and 'Årdberg AB'! + use Text::Unidecode qw(unidecode); + $text = unidecode($text); + + return $text; +} + sub _format_amount { my $self = shift; my $amount = shift; diff --git a/SL/SEPA/XML/Transaction.pm b/SL/SEPA/XML/Transaction.pm index 22f661bb6..83a749e37 100644 --- a/SL/SEPA/XML/Transaction.pm +++ b/SL/SEPA/XML/Transaction.pm @@ -2,8 +2,6 @@ package SL::SEPA::XML::Transaction; use strict; -use SL::DB::Helper::ReplaceSpecialChars qw(replace_special_chars); - use Carp; use Encode; use List::Util qw(first); @@ -37,7 +35,7 @@ sub _init { map { $self->{$_} = $self->{sepa}->{iconv}->convert($params{$_}) } keys %params; map { $self->{$_} =~ s/\s+//g } qw(src_iban src_bic dst_iban dst_bic); - map { $self->{$_} = replace_special_chars($self->{$_}) } qw(company reference end_to_end_id); + map { $self->{$_} = $self->{sepa}->_replace_special_chars($self->{$_}) } qw(company reference end_to_end_id); } sub get { diff --git a/t/bank/bank_transactions.t b/t/bank/bank_transactions.t index 0220c951e..a85a72f3f 100644 --- a/t/bank/bank_transactions.t +++ b/t/bank/bank_transactions.t @@ -1,4 +1,4 @@ -use Test::More tests => 138; +use Test::More tests => 137; use strict; @@ -119,7 +119,7 @@ sub reset_state { )->save; $customer = new_customer( - name => 'Test Customer OLÉ S.L. Årdbärg AB', + name => 'Test Customer', iban => 'DE12500105170648489890', bic => 'TESTBIC', account_number => '648489890', @@ -710,15 +710,6 @@ sub test_sepa_export { vc_depositor => $customer->depositor, amount => $ar_transaction->amount, ); - require SL::SEPA::XML; - my $sepa_xml = SL::SEPA::XML->new('company' => $customer->name, - 'creditor_id' => "id", - 'src_charset' => 'UTF-8', - 'message_id' => "test", - 'grouped' => 1, - 'collection' => 1, - ); - is($sepa_xml->{company} , 'Test Customer OLE S.L. Ardbaerg AB'); $ar_transaction->load; $bt->load; -- 2.20.1