Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Condition atoms with undef values are ignored

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information...
commit 051e0b28e98e4d83b2a33744cd12608bc7b66df9 1 parent d0b80fc
@melo authored
Showing with 8 additions and 4 deletions.
  1. +4 −2 lib/Logan/Filter/Compiler.pm
  2. +4 −2 t/31-filter-compiler.t
View
6 lib/Logan/Filter/Compiler.pm
@@ -203,6 +203,8 @@ sub _compile_condition {
my @expr_atoms;
for my $name (sort keys %$cond) {
my ($check_code, $init_code) = $self->_emit_condition_atom($name, $cond->{$name}, $rule, $m);
+ next unless $check_code;
+
$cond_code .= $init_code if $init_code;
push @expr_atoms, $check_code;
}
@@ -217,11 +219,11 @@ sub _compile_condition {
sub _emit_condition_atom {
my ($self, $name, $value, $rule, $m) = @_;
+ ## FIXME: value == undef is not supported, we ignore it with a warning
+ return unless defined $value;
## IDEA: each atom could be a role that uses after/before on this method and emits the code
if ($name eq 'class' || $name eq 'subclass') {
- ## FIXME: value == undef is a mistake here, this atoms are required
- ## we need to figure out how to report errors first, the fix this FIXME's
my ($id, $is_new) = $m->atom_id_for($name, $value);
my $atom = '$a' . $id;
return ($atom) unless $is_new;
View
6 t/31-filter-compiler.t
@@ -11,6 +11,8 @@ subtest 'condition atom' => sub {
my $c = Logan::Filter::Compiler->new;
my $m = Logan::Filter::Compiler::State->new;
+ cmp_deeply([$c->_emit_condition_atom('class', undef, { class => undef }, $m)], [], 'atom with undef values, skipped');
+
cmp_deeply(
[$c->_emit_condition_atom('class', 'me', { class => 'me' }, $m)],
['$a1', 'my $a1 = $e->{"class"} eq "me";'],
@@ -32,9 +34,9 @@ subtest 'condition code' => sub {
my $m = Logan::Filter::Compiler::State->new;
is_string(
- $c->_compile_condition({ condition => { class => 'log' } }, $m),
+ $c->_compile_condition({ condition => { class => 'log', xpto => undef } }, $m),
'my $a1 = $e->{"class"} eq "log"; if ($a1) ',
- '_compile_condition() generates proper code, incl condition atom init code',
+ '_compile_condition() generates proper code, incl condition atom init code, undef values skipped',
);
is_string(
$c->_compile_condition({ condition => { class => 'log', subclass => 'critical' } }, $m),
Please sign in to comment.
Something went wrong with that request. Please try again.