Skip to content

Commit

Permalink
Item13117: restore support for M (mandatory) and switch the default o…
Browse files Browse the repository at this point in the history
…ver to emptyok. Reduce complexity by only supporting one CHECK set
  • Loading branch information
Comment committed Jan 14, 2015
1 parent 98743e8 commit 8edbfc5
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 126 deletions.
Expand Up @@ -535,16 +535,6 @@ function _id_ify(id) {
}
}

function CHECK_option(spec, option) {
if (!spec.CHECK)
return null;
if (spec.CHECK.length == 0)
return null;
if (!spec.CHECK[0][option])
return null;
return spec.CHECK[0][option][0];
}

// Load a key node UI
function load_ui($node) {
var spec = $node.data('spec.entry'),
Expand Down Expand Up @@ -572,7 +562,7 @@ function _id_ify(id) {
$pending.remove();
}

if (CHECK_option(spec, 'undefok') === 1) {
if (spec.CHECK['undefok'] === 1) {
// If undefined is OK, then we add a checkbox that
// needs to be clicked to see the value input.
// if it isn't checked, the value is undefined; if it
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Configure/Checkers/NUMBER.pm
Expand Up @@ -29,15 +29,15 @@ sub check_current_value {
return;
}

my $check = $this->{item}->{CHECK}->[0] || {};
my $check = $this->{item}->{CHECK};

if ( defined $check->{min} ) {
my $v = eval "$check->{min}[0]";
my $v = eval "$check->{min}";
$reporter->ERROR("Value must be at least $check->{min}[0]")
if ( defined $v && $val < $v );
}
if ( defined $check->{max} ) {
my $v = eval "$check->{max}[0]";
my $v = eval "$check->{max}";
$reporter->ERROR("Value must be no greater than $check->{min}[0]")
if ( defined $v && $val > $v );
}
Expand Down
47 changes: 19 additions & 28 deletions core/lib/Foswiki/Configure/Checkers/PATH.pm
Expand Up @@ -31,12 +31,8 @@ sub check_current_value {
my $path = $this->checkExpandedValue($reporter);
return unless defined $path;

foreach my $check ( @{ $this->{item}->{CHECK} } ) {
my $perms = $check->{perms};

next unless ($perms);
$perms = $perms->[0];

my $perms = $this->{item}->{CHECK}->{perms};
if ( defined $perms ) {
if ( $perms =~ /F/ && !-f $path ) {
if ( -d $path ) {
$reporter->ERROR(
Expand Down Expand Up @@ -80,30 +76,25 @@ sub validate_permissions {
my $missingFile = 0;
my @messages;

foreach my $check ( @{ $this->{item}->{CHECK} } ) {
my $perms = $check->{perms};
my $filter = $check->{filter}[0];

if ($perms) {
my $checkPerms = $perms->[0];
$checkPerms =~ s/d//g if ( $Foswiki::cfg{OS} eq 'WINDOWS' );

if ( $checkPerms =~ /F/ && !-f $path ) {
return $reporter->ERROR("$path is not a plain file");
}
if ( $checkPerms =~ /D/ && !-d $path ) {
return $reporter->ERROR("$path is not a directory");
}
my $perms = $this->{item}->{CHECK}->{perms};
if ( defined $perms ) {
$perms =~ s/d//g if ( $Foswiki::cfg{OS} eq 'WINDOWS' );

my $report =
Foswiki::Configure::FileUtil::checkTreePerms( $path, $checkPerms,
filter => $filter );
$fileCount += $report->{fileCount};
$fileErrors += $report->{fileErrors};
$excessPerms += $report->{excessPerms};
$missingFile += $report->{missingFile};
push( @messages, @{ $report->{messages} } );
if ( $perms =~ /F/ && !-f $path ) {
return $reporter->ERROR("$path is not a plain file");
}
if ( $perms =~ /D/ && !-d $path ) {
return $reporter->ERROR("$path is not a directory");
}

my $report =
Foswiki::Configure::FileUtil::checkTreePerms( $path, $perms,
filter => $this->{item}->{CHECK}->{filter} );
$fileCount += $report->{fileCount};
$fileErrors += $report->{fileErrors};
$excessPerms += $report->{excessPerms};
$missingFile += $report->{missingFile};
push( @messages, @{ $report->{messages} } );
}

my $dperm = sprintf( '%04o', $Foswiki::cfg{Store}{dirPermission} );
Expand Down
20 changes: 10 additions & 10 deletions core/lib/Foswiki/Configure/Checkers/URL.pm
Expand Up @@ -19,7 +19,7 @@ our @ISA = ('Foswiki::Configure::Checker');
# * parts:scheme,authority,path,query,fragment
# Parts allowed in item
# Default: scheme,authority,path
# * notrail = disallow trailing / on (https?) paths
# * trail = allow trailing / on (https?) paths
# * partsreq = Parts required in item
# * schemes = schemes allowd in item
# Default: http,https
Expand All @@ -46,7 +46,7 @@ sub check_current_value {

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

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

sub _list2hash {
Expand All @@ -59,7 +59,7 @@ sub checkURI {
my ( $reporter, $uri, %checks ) = @_;

unless ( defined $uri ) {
$reporter->ERROR("Not a valid URI") unless $checks{undefok}[0];
$reporter->ERROR("Not a valid URI") unless $checks{undefok};
return;
}

Expand All @@ -68,13 +68,13 @@ sub checkURI {
$checks{partsreq} ||= [qw/scheme authority/];
$checks{schemes} ||= [qw/http https/];
$checks{authtype} ||= ['host'];
$checks{notrail} ||= [0];
$checks{pass} ||= [0];
$checks{user} ||= $checks{pass}[0] ? [1] : [0];
$checks{trail} = 1 unless defined $checks{trail};
$checks{pass} = 0 unless defined $checks{pass};
$checks{user} = $checks{pass} unless defined $checks{user};

$uri =~ s/^\s*(.*?)\s*$/$1/ if defined $uri;

return if ( !( defined $uri && length($uri) ) && $checks{undefok}[0] );
return if ( !( defined $uri && length($uri) ) && $checks{undefok} );

unless ( $uri =~ $uriRE ) {
$reporter->ERROR("Syntax error: $uri is not a valid URI");
Expand Down Expand Up @@ -110,9 +110,9 @@ sub checkURI {
my $auth = $authority;
if ( $auth =~ s/^([^:\@]+)(?::[^\@]+)?\@// ) {
my ( $user, $pass ) = ( $1, $2 );
if ( $checks{user}[0] ) {
if ( $checks{user} ) {
if ( defined $pass ) {
unless ( $checks{pass}[0] ) {
unless ( $checks{pass} ) {
$reporter->ERROR(
"Embedded password is not permitted in $uri");
}
Expand Down Expand Up @@ -183,7 +183,7 @@ m{^(?:/|(?:/(?:[~+a-zA-Z0-9\$_\@.&!*"'(),-]|%[[:xdigit:]]{2})+)*/?)$}
{
$reporter->ERROR("Path ($path) is not valid");
}
if ( $checks{notrail}[0] && $path =~ m{/$} ) {
if ( !$checks{trail} && $path =~ m{/$} ) {
$reporter->ERROR("Trailing / not allowed");
}
} # Checks for other schemes?
Expand Down
5 changes: 1 addition & 4 deletions core/lib/Foswiki/Configure/Checkers/URLPATH.pm
Expand Up @@ -15,10 +15,7 @@ sub check_current_value {
my $value = $this->checkExpandedValue($reporter);
return unless defined $value;

my %check = ();
if ( scalar( @{ $this->{item}->{CHECK} } ) > 0 ) {
%check = %{ $this->{item}->{CHECK}->[0] };
}
my %check = %{ $this->{item}->{CHECK} };

# Force the following 'options' to specialize URL to URLPATH.
$check{parts} = [
Expand Down
55 changes: 20 additions & 35 deletions core/lib/Foswiki/Configure/Item.pm
Expand Up @@ -151,12 +151,12 @@ sub _parseOptions {
$spec = $spec->{$key};

die "Bad option '$key' in .spec before $str" unless $spec;
my $val;
if ( $str =~ s/^\s*=// ) {
my $val;
if ( $str =~ s/^\s*((["']).*?[^\\]\2)// ) {
if ( $str =~ s/^\s*(["'])(.*?[^\\])\1// ) {

# =string (must retain quotes)
$val = $1;
# =string
$val = $2;
}
elsif ( $str =~ s/^\s*([A-Z0-9]+)// ) {

Expand All @@ -166,42 +166,27 @@ sub _parseOptions {
else {
die "Parse error when reading .spec options at $key=$str";
}
if ( $spec
&& defined $spec->{parse_val}
&& !$Foswiki::Configure::LoadSpec::RAW_VALS )
{
my $fn = $spec->{parse_val};
$this->$fn($val);
}
else {

# Can shed quotes now
$val =~ s/^(["'])(.*)\1$/$2/;
if ( ref( $this->{$key} ) eq 'ARRAY' ) {
push( @{ $this->{$key} }, $val );
}
else {
$this->{$key} = $val;
}
}
}
elsif ($remove) {
delete $this->{$key};
}
elsif ( $spec->{openclose} ) {
$str =~ s/^(.*?)(\/$key|$)//;
if ( defined $spec->{parse_val}
&& !$Foswiki::Configure::LoadSpec::RAW_VALS )
{
my $fn = $spec->{parse_val};
$this->$fn( $str, $key );
}
else {
$this->{$key} = $1;
}
$val = $1;
}
else {
$val = 1;
}
if ($remove) {
delete $this->{$key};
$val = undef;
}

if ( defined $spec->{handler}
&& !$Foswiki::Configure::LoadSpec::RAW_VALS )
{
my $fn = $spec->{handler};
$this->{key} = $this->$fn( $val, $key );
}
else {
$this->{$key} = 1;
$this->{$key} = $val;
}
}
die "Parse failed at $str" unless $str =~ /^\s*$/;
Expand Down
25 changes: 12 additions & 13 deletions core/lib/Foswiki/Configure/Query.pm
Expand Up @@ -376,17 +376,16 @@ sub check_current_value {
if ($v) {
print STDERR "\t'$k' is a key\n" if TRACE_CHECK;
push( @checko, $v );
if ( $params->{check_dependencies} ) {
if ( $params->{check_dependencies}
&& defined $v->{CHECK}->{also} )
{

# Look at the CHECK="also:" explicit dependencies
foreach my $ch ( @{ $v->{CHECK} } ) {
next unless $ch->{also};
foreach my $dep ( @{ $ch->{also} } ) {
next if $check{$dep};
print STDERR "\t... has a check:also for $dep\n"
if TRACE_CHECK;
push( @keys, $dep ) unless $check{$dep};
}
foreach my $dep ( @{ $v->{CHECK}->{also} } ) {
next if $check{$dep};
print STDERR "\t... has a check:also for $dep\n"
if TRACE_CHECK;
push( @keys, $dep ) unless $check{$dep};
}
}
}
Expand Down Expand Up @@ -423,9 +422,9 @@ sub check_current_value {

SPEC:
foreach my $spec (@checko) {
foreach my $check ( @{ $spec->{CHECK} } ) {
next unless $check->{iff};
my $e = $check->{iff}[0];
my $e = $spec->{CHECK}->{iff};
if ( defined $e ) {
$e = $e->[0];

# Expand {x} as $Foswiki::cfg{x}
$e =~ s/(({[^}]+})+)/\$Foswiki::cfg$1/g;
Expand All @@ -442,7 +441,7 @@ sub check_current_value {
next unless $checker;
ASSERT( $spec->{keys} ) if DEBUG;
$reporter->clear();
$reporter->NOTE("Checking $spec-.{keys}") if $params->{trace};
$reporter->NOTE("Checking $spec->{keys}") if $params->{trace};
$checker->check_current_value($reporter);
my @path = $spec->getPath();
pop(@path); # remove keys
Expand Down

0 comments on commit 8edbfc5

Please sign in to comment.