From 24740da78b23d8f25811eb689f4c7aa6502b45d4 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 13 May 2010 23:28:38 +0000 Subject: [PATCH] Properly handle single-quotes inside of single-quoted text --- PBot/FactoidModuleLauncher.pm | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/PBot/FactoidModuleLauncher.pm b/PBot/FactoidModuleLauncher.pm index eb5b35f3..caf13782 100644 --- a/PBot/FactoidModuleLauncher.pm +++ b/PBot/FactoidModuleLauncher.pm @@ -51,10 +51,14 @@ sub execute_module { my $module = $self->{pbot}->factoids->factoids->{$keyword}{module}; my $module_dir = $self->{pbot}->module_dir; + $self->{pbot}->logger->log("(" . (defined $from ? $from : "(undef)") . "): $nick!$user\@$host: Executing module $module $arguments\n"); $arguments =~ s/\$nick/$nick/g; + $arguments = quotemeta($arguments); + $arguments =~ s/\\\s/ /g; + if(exists $self->{pbot}->factoids->factoids->{$keyword}{modulelauncher_subpattern}) { if($self->{pbot}->factoids->factoids->{$keyword}{modulelauncher_subpattern} =~ m/s\/(.*?)\/(.*)\//) { my ($p1, $p2) = ($1, $2); @@ -86,30 +90,27 @@ sub execute_module { } } - my $unquoted_args = $arguments; + my $argsbuf = $arguments; $arguments = ""; - while($unquoted_args =~ s/(.*?)('.*)//) { - my $prefix = $1; - my $remainder = $2; + my $lr; + while(1) { + my ($e, $r, $p) = extract_delimited($argsbuf, "'", "[^']+"); - $arguments .= quotemeta($prefix); - - my ($e, $r) = extract_delimited($remainder, "'"); - - if(not defined $e) { - $arguments .= quotemeta($r); - } else { + if(defined $e) { + $e =~ s/\\//g; + $e =~ s/'/'\\''/g; + $e =~ s/^'\\''/'/; + $e =~ s/'\\''$/'/; + $arguments .= $p; $arguments .= $e; - $unquoted_args = $r; + $lr = $r; + } else { + $arguments .= $lr; + last; } } - $arguments .= $unquoted_args; - - $arguments =~ s/\\\s/ /g; - $arguments =~ s/\\-/-/g; - my $pid = fork; if(not defined $pid) { $self->{pbot}->logger->log("Could not fork module: $!\n");