Skip to content

Commit

Permalink
Merge pull request #918 from drgrice1/EV3P-protect-command-output
Browse files Browse the repository at this point in the history
Protect EV3P command output from variable substitution.
  • Loading branch information
drdrew42 authored Oct 2, 2023
2 parents 0b1f3ac + 54dc0ee commit c8344f9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions macros/core/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,12 @@ sub safe_ev {
($out, $PG_eval_errors, $PG_full_error_report);
}

sub safe_evp {
my @result = &safe_ev;
$result[0] = '${__blank__}' . $result[0] . '${__blank__}';
return @result;
}

sub old_safe_ev {
my $in = shift;
my ($out, $PG_eval_errors, $PG_full_error_report) = PG_restricted_eval($in);
Expand Down Expand Up @@ -2289,12 +2295,13 @@ sub EV3P {
%{$option_ref},
);
my $string = join(" ", @_);
$string = ev_substring($string, "\\\\{", "\\\\}", \&safe_ev) if $options{processCommands};
$string = ev_substring($string, "\\\\{", "\\\\}", $options{processVariables} ? \&safe_evp : \&safe_ev)
if $options{processCommands};
if ($options{processVariables}) {
my $eval_string = $string;
$eval_string =~ s/\$(?![a-z\{])/\${DOLLAR}/gi if $options{fixDollars};
my ($evaluated_string, $PG_eval_errors, $PG_full_errors) =
PG_restricted_eval("<<END_OF_EVALUATION_STRING\n$eval_string\nEND_OF_EVALUATION_STRING\n");
my ($evaluated_string, $PG_eval_errors, $PG_full_errors) = PG_restricted_eval(
q{my $__blank__ = '';} . "<<END_OF_EVALUATION_STRING\n$eval_string\nEND_OF_EVALUATION_STRING\n");
if ($PG_eval_errors) {
my $error = (split("\n", $PG_eval_errors))[0];
$error =~ s/at \(eval.*//gs;
Expand Down

0 comments on commit c8344f9

Please sign in to comment.