Skip to content

Commit 244b0f6

Browse files
authored
Merge pull request #847 from ikedas/issue-844 by ikedas
Additional fixes to #841.
2 parents 88e81ba + 2aace48 commit 244b0f6

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/lib/Sympa/Scenario.pm

+23-10
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,10 @@ sub _compile_condition {
678678
}
679679
} elsif ($value =~ /\[custom_vars\-\>([\w\-]+)\]/i) {
680680
# Custom vars
681-
$value = sprintf '$context->{custom_vars}{%1}', $1;
681+
$value = sprintf '$context->{custom_vars}{\'%s\'}', $1;
682682
} elsif ($value =~ /\[family\-\>([\w\-]+)\]/i) {
683683
# Family vars
684-
$value = sprintf '$context->{family}{%s}', $1;
684+
$value = sprintf '$context->{family}{\'%s\'}', $1;
685685
} elsif ($value =~ /\[conf\-\>([\w\-]+)\]/i) {
686686
# Config param
687687
my $conf_key = $1;
@@ -725,7 +725,7 @@ sub _compile_condition {
725725
if ( exists $pinfo->{$canon_param}
726726
and ref $pinfo->{$canon_param}{format} ne 'HASH'
727727
and $pinfo->{$canon_param}{occurrence} !~ /n$/) {
728-
$value = sprintf '$that->{admin}{%s}', $canon_param;
728+
$value = sprintf '$that->{admin}{\'%s\'}', $canon_param;
729729
} else {
730730
$log->syslog('err',
731731
'Unknown list parameter %s in rule %s',
@@ -741,19 +741,19 @@ sub _compile_condition {
741741
my $key = $1;
742742
$value =
743743
sprintf
744-
'($context->{user} || Sympa::User->new($context->{sender}))->{%s}',
744+
'($context->{user} || Sympa::User->new($context->{sender}))->{\'%s\'}',
745745
$key;
746746
} elsif ($value =~ /\[user_attributes\-\>([\w\-]+)\]/i) {
747747
my $key = $1;
748748
$value =
749749
sprintf
750-
'($context->{user} || Sympa::User->new($context->{sender}))->{attributes}{%s}',
750+
'($context->{user} || Sympa::User->new($context->{sender}))->{attributes}{\'%s\'}',
751751
$key;
752752
} elsif ($value =~ /\[subscriber\-\>([\w\-]+)\]/i) {
753753
my $key = $1;
754754
$value =
755755
sprintf
756-
'($context->{subscriber} || $that->get_list_memner($context->{sender}) || {})->{%s}',
756+
'($context->{subscriber} || $that->get_list_memner($context->{sender}) || {})->{\'%s\'}',
757757
$key;
758758
} elsif ($value =~
759759
/\[(msg_header|header)\-\>([\w\-]+)\](?:\[([-+]?\d+)\])?/i) {
@@ -907,8 +907,9 @@ sub _compile_condition_term {
907907
return sprintf '(%s =~ %s)', $args[0], $args[1];
908908
}
909909
} elsif ($condition_key =~ /^customcondition::(\w+)$/) {
910-
return sprintf 'do_verify_custom($that, %s, %s, %s)',
911-
_compile_hashref($rule), $1, join ', ', @args;
910+
my $mod = $1;
911+
return sprintf 'do_verify_custom($that, %s, \'%s\', %s)',
912+
_compile_hashref($rule), $mod, join ', ', @args;
912913
} else {
913914
$log->syslog('err', 'Syntax error: Unknown condition %s',
914915
$condition_key);
@@ -926,8 +927,20 @@ sub _compile_hashref {
926927
', ',
927928
map {
928929
my ($k, $v) = ($_, $hashref->{$_});
929-
$v =~ s/([\\\'])/\\$1/g;
930-
sprintf "%s => '%s'", $k, $v;
930+
if (ref $v eq 'ARRAY') {
931+
$v = join(
932+
', ',
933+
map {
934+
my $i = $_;
935+
$i =~ s/([\\\'])/\\$1/g;
936+
"'$i'";
937+
} @$v
938+
);
939+
sprintf '%s => [%s]', $k, $v;
940+
} else {
941+
$v =~ s/([\\\'])/\\$1/g;
942+
sprintf "%s => '%s'", $k, $v;
943+
}
931944
} sort keys %$hashref
932945
) . '}';
933946
}

0 commit comments

Comments
 (0)