3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-29 23:39:24 +01:00

compiler_vm: improve escaping of quotes

This commit is contained in:
Pragmatic Software 2019-06-24 19:01:38 -07:00
parent 8e21de1f60
commit 4176849e37
3 changed files with 23 additions and 13 deletions

View File

@ -443,10 +443,10 @@ sub add_option {
sub process_standard_options {
my $self = shift;
my @opt_args = $self->split_line($self->{code});
my @opt_args = $self->split_line($self->{code}, preserve_escapes => 0);
use Data::Dumper;
print STDERR Dumper \@opt_args;
print STDERR "opt_arg: ", Dumper \@opt_args;
my $getopt_error;
local $SIG{__WARN__} = sub {
@ -463,7 +463,7 @@ sub process_standard_options {
print STDERR "getopt: ret: [$ret]: rest: [$rest], info: $info, input: $input, args: $arguments, paste: $paste\n";
print STDERR Dumper @opt_args;
# print STDERR Dumper \@opt_args;
if ($info) {
my $cmdline = $self->{cmdline};
@ -1026,7 +1026,8 @@ sub split_line {
my %default_opts = (
strip_quotes => 0,
keep_spaces => 0
keep_spaces => 0,
preserve_escapes => 1,
);
%opts = (%default_opts, %opts);
@ -1067,7 +1068,11 @@ sub split_line {
$spaces = 0 if $ch ne ' ';
if ($escaped) {
$token .= "\\$ch";
if ($opts{preserve_escapes}) {
$token .= "\\$ch";
} else {
$token .= $ch;
}
$escaped = 0;
next;
}
@ -1091,7 +1096,7 @@ sub split_line {
next;
}
if ($last_ch eq ' ' and not defined $quote and ($ch eq "'" or $ch eq '"')) {
if (($last_ch eq ' ' or $last_ch eq ':' or $last_ch eq '(') and not defined $quote and ($ch eq "'" or $ch eq '"')) {
if ($ignore_quote) {
# treat unbalanced quote as part of this argument
$token .= $ch;

View File

@ -19,7 +19,7 @@ sub preprocess {
$self->execute(10, undef, 'date', '-s', "\@$self->{date}");
my @cmd = $self->split_line($self->{cmdline}, strip_quotes => 1);
my @cmd = $self->split_line($self->{cmdline}, strip_quotes => 1, preserve_escapes => 0);
if ($self->{code} =~ m/print_last_statement\(.*\);$/m) {
# remove print_last_statement wrapper in order to get warnings/errors from last statement line
@ -75,7 +75,7 @@ sub postprocess {
}
print "Executing gdb\n";
my @args = $self->split_line($self->{arguments}, strip_quotes => 1);
my @args = $self->split_line($self->{arguments}, strip_quotes => 1, preserve_escapes => 0);
my ($exitval, $stdout, $stderr) = $self->execute(60, undef, 'compiler_watchdog.pl', @args);
my $result = $stderr;

View File

@ -44,8 +44,8 @@ sub preprocess {
$self->execute(10, undef, 'date', '-s', "\@$self->{date}");
print "Executing [$self->{cmdline}] with args [$self->{arguments}]\n";
my @cmdline = $self->split_line($self->{cmdline}, strip_quotes => 1);
push @cmdline, $self->split_line($self->{arguments}, strip_quotes => 1);
my @cmdline = $self->split_line($self->{cmdline}, strip_quotes => 1, preserve_escapes => 0);
push @cmdline, $self->split_line($self->{arguments}, strip_quotes => 1, preserve_escapes => 0);
my ($retval, $stdout, $stderr) = $self->execute(60, $self->{input}, @cmdline);
$self->{output} = $stderr;
@ -89,7 +89,8 @@ sub split_line {
my %default_opts = (
strip_quotes => 0,
keep_spaces => 0
keep_spaces => 0,
preserve_escapes => 1,
);
%opts = (%default_opts, %opts);
@ -130,7 +131,11 @@ sub split_line {
$spaces = 0 if $ch ne ' ';
if ($escaped) {
$token .= "\\$ch";
if ($opts{preserve_escapes}) {
$token .= "\\$ch";
} else {
$token .= $ch;
}
$escaped = 0;
next;
}
@ -154,7 +159,7 @@ sub split_line {
next;
}
if ($last_ch eq ' ' and not defined $quote and ($ch eq "'" or $ch eq '"')) {
if (($last_ch eq ' ' or $last_ch eq ':' or $last_ch eq '(') and not defined $quote and ($ch eq "'" or $ch eq '"')) {
if ($ignore_quote) {
# treat unbalanced quote as part of this argument
$token .= $ch;