Subject: | filter split broken constraint minmaxfields |
because filter Split always return an array even if no value is given,
constraint MinMaxFields doesn't work as expected.
since it changes filter Split's behaviour, hope that the patch is
acceptable.
--
http://islue.blogspot.com/
Subject: | constraint_minmaxfields_with_filter_split.t |
use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
my $form = HTML::FormFu->new;
$form->load_config_file('t/constraint_minmaxfields_with_filter_split.yml');
# Valid
{
$form->process( {
foo => '',
bar => '',
baz => '',
} );
ok( !$form->has_errors );
$form->process( {
foo => '1',
bar => '',
baz => '',
} );
ok( !$form->has_errors );
$form->process( {
foo => '1,2',
bar => '',
baz => '',
} );
ok( !$form->has_errors );
}
# Invalid
{
$form->process( {
foo => 1,
bar => '',
baz => 2,
} );
ok( $form->has_errors );
ok( !$form->valid('foo') );
ok( $form->valid('bar') );
ok( $form->valid('baz') );
}
Subject: | constraint_minmaxfields_with_filter_split.yml |
---
elements:
- name: foo
constraints:
- type: MinMaxFields
others:
- bar
- baz
min: 0
max: 1
filters:
- type: Split
regex: ','
- name: bar
filters:
- type: Split
regex: ','
- name: baz
filters:
- type: Split
regex: ','
Subject: | HTML-FormFu-Filter-Split.diff |
20c20,22
< return \@values;
---
> return if !scalar @values;
>
> return $#values ? \@values : pop @values;