Navigation Menu

Skip to content

Commit

Permalink
Item13186: drop nullok and support undefok and emptyok instead, to re…
Browse files Browse the repository at this point in the history
…present valid undef and empty string values respectively. Clean up the way check options are used in the checkers, and collapse undef and empty checking into a single checker function. Include other changes from George's patch in the task.
  • Loading branch information
Comment committed Jan 9, 2015
1 parent 3d6fc31 commit a6036b1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
11 changes: 5 additions & 6 deletions core/lib/Foswiki/Configure/Checker.pm
Expand Up @@ -365,13 +365,13 @@ sub checkExpandedValue {
my $field = $value;

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

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

Expand All @@ -380,10 +380,9 @@ sub checkExpandedValue {
}

if ( $field =~ /\n/ ) {
$reporter->NOTE( 'Expands to: <verbatim>',
$field, '</verbatim>' );
$reporter->NOTE( 'Expands to: <verbatim>', $field, '</verbatim>' );
}
elsif ($field eq '') {
elsif ( $field eq '' ) {
$reporter->NOTE("Expands to: '' (empty)");
}
else {
Expand All @@ -393,7 +392,7 @@ sub checkExpandedValue {
}

sub CHECK_option {
my ($this, $opt) = @_;
my ( $this, $opt ) = @_;
my $check = $this->{item}->{CHECK}->[0];
return undef unless $check;
return $check->{$opt}[0];
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Configure/Checkers/DATE.pm
Expand Up @@ -25,7 +25,7 @@ sub check_current_value {
my $value = $this->checkExpandedValue($reporter);
return unless defined $value;

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

if ( $value =~ /\S/ ) {
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Configure/Checkers/SMTP/SENDERHOST.pm
Expand Up @@ -13,8 +13,8 @@ sub check_current_value {
my ( $this, $reporter ) = @_;

return
unless ( $Foswiki::cfg{EnableEmail}
&& $Foswiki::cfg{Email}{MailMethod} =~ /^Net::SMTP/);
unless ( $Foswiki::cfg{EnableEmail}
&& $Foswiki::cfg{Email}{MailMethod} =~ /^Net::SMTP/ );

my $value = $this->checkExpandedValue();
return unless defined $value;
Expand Down
6 changes: 1 addition & 5 deletions core/lib/Foswiki/Configure/Checkers/URL.pm
Expand Up @@ -46,11 +46,7 @@ sub check_current_value {

my $val = $this->checkExpandedValue($reporter);

checkURI(
$reporter,
$val,
%{ $this->{item}->{CHECK}->[0] || {} }
);
checkURI( $reporter, $val, %{ $this->{item}->{CHECK}->[0] || {} } );
}

sub _list2hash {
Expand Down
4 changes: 1 addition & 3 deletions core/lib/Foswiki/Configure/Value.pm
Expand Up @@ -99,9 +99,7 @@ our %CHECK_options = (
schemes => -1, # for URL
);

our %rename_options = (
nullok => 'undefok'
);
our %rename_options = ( nullok => 'undefok' );

=begin TML
Expand Down
10 changes: 6 additions & 4 deletions core/lib/Foswiki/Configure/Wizards/Save.pm
Expand Up @@ -249,14 +249,15 @@ sub save {
eval "undef \$Foswiki::cfg$k";
}
}
elsif ($spec->CHECK_option('nullok')) {
elsif ( $spec->CHECK_option('nullok') ) {
eval "undef \$Foswiki::cfg$k";
}
else {
$reporter->ERROR(
"SAVE ABORTED: undef given as value for $k, but the spec is not undefok");
"SAVE ABORTED: undef given as value for $k, but the spec is not undefok"
);
return undef;
}
}
ASSERT( !$@, $@ ) if DEBUG;
}
}
Expand Down Expand Up @@ -430,7 +431,8 @@ sub _generateLSC {
# An undef value and undefok will suppress the item in LSC
return () if $vs->CHECK_option('undefok');

} elsif ( $datum eq '' ) {
}
elsif ( $datum eq '' ) {

# Treat '' as undef unless emptyok
return () unless $vs->CHECK_option('emptyok');
Expand Down

0 comments on commit a6036b1

Please sign in to comment.