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

Interpreter: escaped spaces behave better

This commit is contained in:
Pragmatic Software 2024-05-26 17:44:59 -07:00
parent c6e1da1706
commit 80f9ea1acd
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
5 changed files with 24 additions and 11 deletions

BIN
data/factoids.sqlite3 vendored

Binary file not shown.

View File

@ -74,11 +74,13 @@ sub launch_applet($self, $context) {
my ($exitval, $stdout, $stderr) = eval { my ($exitval, $stdout, $stderr) = eval {
my $args = $context->{arguments}; my $args = $context->{arguments};
my $strip_quotes = 1; my $strip_quotes = 1;
my $preserve_escapes = 0;
$strip_quotes = 0 if $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, 'keep-quotes'); $strip_quotes = 0 if $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, 'keep-quotes');
$preserve_escapes = 1 if $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, 'keep-escapes');
my @cmdline = ("./$applet", $self->{pbot}->{interpreter}->split_line($args, strip_quotes => $strip_quotes)); my @cmdline = ("./$applet", $self->{pbot}->{interpreter}->split_line($args, strip_quotes => $strip_quotes, preserve_escapes => $preserve_escapes));
my $timeout = $self->{pbot}->{registry}->get_value('general', 'applet_timeout') // 30; my $timeout = $self->{pbot}->{registry}->get_value('general', 'applet_timeout') // 30;

View File

@ -28,6 +28,7 @@ our %factoid_metadata = (
'help' => 'TEXT', 'help' => 'TEXT',
'interpolate' => 'INTEGER', 'interpolate' => 'INTEGER',
'keep-quotes' => 'INTEGER', 'keep-quotes' => 'INTEGER',
'keep-escapes' => 'INTEGER',
'keyword_override' => 'TEXT', 'keyword_override' => 'TEXT',
'last_referenced_in' => 'TEXT', 'last_referenced_in' => 'TEXT',
'last_referenced_on' => 'NUMERIC', 'last_referenced_on' => 'NUMERIC',

View File

@ -292,7 +292,7 @@ sub interpret($self, $context) {
} }
# convert command string to list of arguments # convert command string to list of arguments
my $cmdlist = $self->make_args($context->{command}); my $cmdlist = $self->make_args($context->{command}, preserve_escapes => 1);
$context->{cmdlist} = $cmdlist; $context->{cmdlist} = $cmdlist;
@ -1176,7 +1176,7 @@ sub split_line($self, $line, %opts) {
my %default_opts = ( my %default_opts = (
strip_quotes => 0, strip_quotes => 0,
keep_spaces => 0, keep_spaces => 0,
preserve_escapes => 1, preserve_escapes => 0,
strip_commas => 0, strip_commas => 0,
); );
@ -1224,8 +1224,11 @@ sub split_line($self, $line, %opts) {
$spaces = 0 if $ch ne ' '; $spaces = 0 if $ch ne ' ';
if ($escaped) { if ($escaped) {
if ($opts{preserve_escapes}) { $token .= "\\$ch"; } if ($opts{preserve_escapes}) {
else { $token .= $ch; } $token .= "\\$ch";
} else {
$token .= $ch;
}
$escaped = 0; $escaped = 0;
next; next;
} }
@ -1284,8 +1287,15 @@ sub split_line($self, $line, %opts) {
} }
# creates an array of arguments from a string # creates an array of arguments from a string
sub make_args($self, $string) { sub make_args($self, $string, %opts) {
my @args = $self->split_line($string, keep_spaces => 1); my %default_opts = (
keep_spaces => 1,
preserve_escapes => 0,
);
%opts = (%default_opts, %opts);
my @args = $self->split_line($string, keep_spaces => $opts{keep_spaces}, preserve_escapes => $opts{preserve_escapes});
my @arglist; my @arglist;
my @arglist_unstripped; my @arglist_unstripped;

View File

@ -25,8 +25,8 @@ use PBot::Imports;
# These are set by the /misc/update_version script # These are set by the /misc/update_version script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 4754, BUILD_REVISION => 4755,
BUILD_DATE => "2024-05-16", BUILD_DATE => "2024-05-26",
}; };
sub initialize {} sub initialize {}