From f2b3e089d77206252a24be4f565c608d28f88c12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Thu, 15 Mar 2018 21:40:10 +0100 Subject: [PATCH] DATEV/CSV check_encoding, sollte wirklich das encoding checken MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Entsprechend vier Testfälle für die Routine gesetzt und Hintergründe in #348 dokumentiert. --- SL/DATEV/CSV.pm | 4 ++-- t/datev/encoding.t | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 t/datev/encoding.t diff --git a/SL/DATEV/CSV.pm b/SL/DATEV/CSV.pm index 69448c49f..4e164754a 100644 --- a/SL/DATEV/CSV.pm +++ b/SL/DATEV/CSV.pm @@ -3,7 +3,7 @@ package SL::DATEV::CSV; use strict; use Carp; use DateTime; -use Encode qw(decode); +use Encode qw(encode); use Scalar::Util qw(looks_like_number); use SL::DB::Datev; @@ -260,7 +260,7 @@ sub check_encoding { my ($test) = @_; return undef unless $test; if (eval { - decode('Windows-1252', $test, Encode::FB_CROAK|Encode::LEAVE_SRC); + encode('Windows-1252', $test, Encode::FB_CROAK|Encode::LEAVE_SRC); 1 }) { return 1; diff --git a/t/datev/encoding.t b/t/datev/encoding.t new file mode 100644 index 000000000..3c3369a6b --- /dev/null +++ b/t/datev/encoding.t @@ -0,0 +1,23 @@ +use strict; +use Test::More; + +use lib 't'; + +use_ok 'Support::TestSetup'; +use SL::DATEV::CSV qw(check_text); +use Support::TestSetup; + +use utf8; +Support::TestSetup::login(); + +my $ascii = 'foobar 443334 hallo'; +my $german = 'üßäüö €'; +my $croatia = 'Kulašić hat viele €'; +my $armenian = 'Հայերեն ֏'; + +is 1, SL::DATEV::CSV::check_encoding($ascii), 'ASCII Encoding'; +is 1, SL::DATEV::CSV::check_encoding($german), 'German umlaut, euro and ligatur Encoding'; +is undef, SL::DATEV::CSV::check_encoding($croatia), 'croatia with euro Encoding'; +is undef, SL::DATEV::CSV::check_encoding($armenian), 'armenian Encoding'; + +done_testing; -- 2.20.1