From: Sven Schöling Date: Fri, 1 Apr 2016 14:54:21 +0000 (+0200) Subject: ParseFilter: neuer Filter "trim" X-Git-Tag: release-3.4.1~263 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=abc7a54cc16668a7803b574c44bddac9ec2abaa3;p=kivitendo-erp.git ParseFilter: neuer Filter "trim" Ausserdem autotrim bei substr, head und tail Filtern --- diff --git a/SL/Controller/Helper/ParseFilter.pm b/SL/Controller/Helper/ParseFilter.pm index 2ff97987c..c642abf55 100644 --- a/SL/Controller/Helper/ParseFilter.pm +++ b/SL/Controller/Helper/ParseFilter.pm @@ -8,6 +8,7 @@ our @EXPORT = qw(parse_filter); use DateTime; use SL::Helper::DateTime; use List::MoreUtils qw(uniq); +use SL::Util qw(trim); use SL::MoreCommon qw(listify); use Data::Dumper; use Text::ParseWords; @@ -24,9 +25,10 @@ my %filters = ( date => sub { DateTime->from_lxoffice($_[0]) }, number => sub { $::form->parse_amount(\%::myconfig, $_[0]) }, percent => sub { $::form->parse_amount(\%::myconfig, $_[0]) / 100 }, - head => sub { $_[0] . '%' }, - tail => sub { '%' . $_[0] }, - substr => sub { '%' . $_[0] . '%' }, + head => sub { trim($_[0]) . '%' }, + tail => sub { '%' . trim($_[0]) }, + substr => sub { '%' . trim($_[0]) . '%' }, + trim => sub { trim($_[0]) }, ); my %methods = ( @@ -432,22 +434,22 @@ Pasres the input string with C<< Form->parse_amount >> Parses the input string with C<< Form->parse_amount / 100 >> +=item trim + +Removes whitespace characters (to be precice, characters with the \p{WSpace} +property from beginning and end of the value. + =item head -Adds "%" at the end of the string. +Adds "%" at the end of the string and applies C. =item tail -Adds "%" at the end of the string. +Adds "%" at the end of the string and applies C. =item substr -Adds "% .. %" around the search string. - -=item eq_ignore_empty - -Ignores this item if it's empty. Otherwise compares it with the -standard SQL C<=> operator. +Adds "% .. %" around the search string and applies C. =back @@ -472,6 +474,11 @@ be completely removed from the query. Otherwise a falsish filter value will match for C and C; trueish values will only match C. +=item eq_ignore_empty + +Ignores this item if it's empty. Otherwise compares it with the +standard SQL C<=> operator. + =back =head1 BUGS AND CAVEATS diff --git a/t/controllers/helpers/parse_filter.t b/t/controllers/helpers/parse_filter.t index 2c10d036b..0d3db7feb 100644 --- a/t/controllers/helpers/parse_filter.t +++ b/t/controllers/helpers/parse_filter.t @@ -1,6 +1,6 @@ use lib 't'; -use Test::More tests => 38; +use Test::More tests => 41; use Test::Deep; use Data::Dumper; @@ -420,3 +420,21 @@ test { with_objects => [ 'part' ], }, 'complex methods modifying the key'; + +test { + 'customer:substr::ilike' => ' Meyer' +}, { + query => [ customer => { ilike => '%Meyer%' } ] +}, 'auto trim 1'; + +test { + 'customer:head::ilike' => ' Meyer ' +}, { + query => [ customer => { ilike => 'Meyer%' } ] +}, 'auto trim 2'; + +test { + 'customer:tail::ilike' => "\nMeyer\x{a0}" +}, { + query => [ customer => { ilike => '%Meyer' } ] +}, 'auto trim 2';