Use proper lookbehind to prevent expansion of escaped variables

Remove adlib recursion loop since using $action already enables
recursion since subsitution on $action resets the regex position
This commit is contained in:
Pragmatic Software 2015-04-03 13:06:24 -07:00
parent d2711956d6
commit d1341ab4bd
1 changed files with 16 additions and 18 deletions

View File

@ -481,26 +481,24 @@ sub interpreter {
$action =~ s/\$nick/$nick/g;
$action =~ s/\$channel/$from/g;
my $adlib_recursion = 0;
while ($action =~ /[^\\]\$([a-zA-Z0-9_\-]+)/ and ++$adlib_recursion < 5) {
while ($action =~ /[^\\]\$([a-zA-Z0-9_\-]+)/g) {
my $v = $1;
next if $v =~ m/^[0-9]+$/;
my ($var_chan, $var) = $self->find_factoid($from, $v, undef, 0, 1);
while ($action =~ /(?<!\\)\$([a-zA-Z0-9_\-]+)/g) {
my $v = $1;
print "v = [$v]\n";
next if $v =~ m/^[0-9]+$/;
my ($var_chan, $var) = $self->find_factoid($from, $v, undef, 0, 1);
if(defined $var && $self->{factoids}->hash->{$var_chan}->{$var}->{type} eq 'text') {
my $change = $self->{factoids}->hash->{$var_chan}->{$var}->{action};
my @list = split(/\s|(".*?")/, $change);
my @mylist;
for(my $i = 0; $i <= $#list; $i++) {
push @mylist, $list[$i] if $list[$i];
}
my $line = int(rand($#mylist + 1));
$mylist[$line] =~ s/"//g;
$action =~ s/\$$var/$mylist[$line]/;
} else {
$action =~ s/\$$var/$var/g;
if(defined $var && $self->{factoids}->hash->{$var_chan}->{$var}->{type} eq 'text') {
my $change = $self->{factoids}->hash->{$var_chan}->{$var}->{action};
my @list = split(/\s|(".*?")/, $change);
my @mylist;
for(my $i = 0; $i <= $#list; $i++) {
push @mylist, $list[$i] if $list[$i];
}
my $line = int(rand($#mylist + 1));
$mylist[$line] =~ s/"//g;
$action =~ s/\$$var/$mylist[$line]/;
} else {
$action =~ s/\$$var/$var/g;
}
}