Skip to content

Commit

Permalink
Item13186: CHECK_option was in the wrong place
Browse files Browse the repository at this point in the history
  • Loading branch information
Comment committed Jan 10, 2015
1 parent 198f7ce commit dec104e
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 27 deletions.
13 changes: 3 additions & 10 deletions core/lib/Foswiki/Configure/Checker.pm
Expand Up @@ -352,7 +352,7 @@ sub warnAboutWindowsBackSlashes {

=begin TML
---++ PROTECTED ObjectMethod checkExpandedValue($reporter)
---++ PROTECTED ObjectMethod checkExpandedValue($reporter) -> $value
Report the expanded value of a parameter. Return the expanded value.
Expand All @@ -365,13 +365,13 @@ sub checkExpandedValue {
my $field = $value;

if ( !defined $field ) {
if ( !$this->CHECK_option('undefok') ) {
if ( !$this->{item}->CHECK_option('undefok') ) {
$reporter->ERROR("May not be undefined");
}
$field = 'undef';
}

if ( $field eq '' && !$this->CHECK_option('emptyok') ) {
if ( $field eq '' && !$this->{item}->CHECK_option('emptyok') ) {
$reporter->ERROR("May not be empty");
}

Expand All @@ -391,13 +391,6 @@ sub checkExpandedValue {
return $value;
}

sub CHECK_option {
my ( $this, $opt ) = @_;
my $check = $this->{item}->{CHECK}->[0];
return undef unless $check;
return $check->{$opt}[0];
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down
Expand Up @@ -42,11 +42,11 @@ sub checkEnabled {
}

if ( defined $value ) {
my $filter = $this->CHECK_option('filter');
my $filter = $this->{item}->CHECK_option('filter');
$reporter->ERROR("Password contains illegal characters")
if ( defined $filter && $value =~ qr{$filter} );

my $min = $this->CHECK_option('min');
my $min = $this->{item}->CHECK_option('min');
$reporter->ERROR("Password must be at least $min characters long")
if ( defined $min && length($value) < $min );
}
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Configure/Checkers/DATE.pm
Expand Up @@ -25,8 +25,8 @@ sub check_current_value {
my $value = $this->checkExpandedValue($reporter);
return unless defined $value;

my $zone = $this->CHECK_option('zone') || 'utc';
my $normalize = !$this->CHECK_option('raw');
my $zone = $this->{item}->CHECK_option('zone') || 'utc';
my $normalize = !$this->{item}->CHECK_option('raw');

if ( $value =~ /\S/ ) {
my $binval = Foswiki::Time::parseTime( $value, $zone eq 'local' );
Expand All @@ -42,7 +42,7 @@ sub check_current_value {
$reporter->ERROR("Unrecognized format for date");
}
}
elsif ( !$this->CHECK_option('emptyok') ) {
elsif ( !$this->{item}->CHECK_option('emptyok') ) {
$reporter->ERROR('A date/time must be provided for this item');
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Configure/Checkers/EMAILADDRESS.pm
Expand Up @@ -22,14 +22,14 @@ sub check_current_value {
my $value = $this->checkExpandedValue($reporter);
return unless defined $value;

my $list = $this->CHECK_option('list');
my $list = $this->{item}->CHECK_option('list');

my @addrs;
@addrs = split( /,\s*/, $value ) if ( defined $list );
push @addrs, $value unless ( defined $list );

$reporter->ERROR("An e-mail address is required")
unless ( @addrs || $this->CHECK_option('undefok') );
unless ( @addrs || $this->{item}->CHECK_option('undefok') );

foreach my $addr (@addrs) {
$reporter->WARN("\"$addr\" does not appear to be an e-mail address")
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Configure/Checkers/OCTAL.pm
Expand Up @@ -23,13 +23,13 @@ sub check_current_value {
my $val = $this->checkExpandedValue($reporter);
return unless defined $val;

my $min = $this->CHECK_option('min');
my $min = $this->{item}->CHECK_option('min');
if ( defined $min ) {
my $v = eval "0$min";
$reporter->ERROR("Value must be at least $min")
if ( defined $v && $val < $v );
}
my $max = $this->CHECK_option('max');
my $max = $this->{item}->CHECK_option('max');
if ( defined $max ) {
my $v = eval "0$max";
$reporter->ERROR("Value must be no greater than $max")
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Configure/Checkers/PERL.pm
Expand Up @@ -12,7 +12,7 @@ sub check_current_value {

my $value = $this->{item}->getRawValue();
if ( !defined $value ) {
unless ( $this->CHECK_option('undefok') ) {
unless ( $this->{item}->CHECK_option('undefok') ) {
$reporter->ERROR('May not be undefined');
}
return;
Expand Down
8 changes: 4 additions & 4 deletions core/lib/Foswiki/Configure/Checkers/STRING.pm
Expand Up @@ -28,11 +28,11 @@ sub check_current_value {

my $len = length($value);

my $min = $this->CHECK_option('min');
my $max = $this->CHECK_option('max');
my $min = $this->{item}->CHECK_option('min');
my $max = $this->{item}->CHECK_option('max');

my $accept = $this->CHECK_option('accept');
my $filter = $this->CHECK_option('filter');
my $accept = $this->{item}->CHECK_option('accept');
my $filter = $this->{item}->CHECK_option('filter');

if ( defined $min && $len < $min ) {
$reporter->ERROR("Length must be at least $min");
Expand Down
23 changes: 23 additions & 0 deletions core/lib/Foswiki/Configure/Value.pm
Expand Up @@ -404,6 +404,29 @@ sub decodeValue {
return $value;
}

=begin TML
---++ ObjectMethod CHECK_option($keyname) -> $value
Return the first value of the first CHECK option that contains
the key =$opt=
e.g. if we have =CHECK="a b" CHECK="c d=99 e"= in the .spec
then =CHECK_option('c')= will return true and
=CHECK_option('d')= will return =99=
=cut

sub CHECK_option {
my ( $this, $opt ) = @_;
foreach my $check ( @{ $this->{CHECK} } ) {
if ( $check->{$opt} ) {
return $check->{$opt}[0];
}
}
return undef;
}

# Implements Foswiki::Configure::item
sub search {
my ( $this, $re ) = @_;
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Configure/Wizards/Save.pm
Expand Up @@ -249,7 +249,7 @@ sub save {
eval "undef \$Foswiki::cfg$k";
}
}
elsif ( $spec->CHECK_option('nullok') ) {
elsif ( $spec->{item}->CHECK_option('nullok') ) {
eval "undef \$Foswiki::cfg$k";
}
else {
Expand Down Expand Up @@ -430,14 +430,14 @@ sub _generateLSC {

# An undef value and undefok will suppress the item in LSC
return ()
if ( $vs->can('CHECK_option') && $vs->CHECK_option('undefok') );
if ( $vs->{item}->CHECK_option('undefok') );

}
elsif ( $datum eq '' ) {

# Treat '' as undef unless emptyok
return ()
if ( $vs->can('CHECK_option') && $vs->CHECK_option('emptyok') );
if ( $vs->{item}->CHECK_option('emptyok') );
}
my $d = Foswiki::Configure::Reporter::uneval($datum);
push( @dump, "\$Foswiki::cfg$keys = $d;\n" );
Expand Down

0 comments on commit dec104e

Please sign in to comment.