mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-25 12:12:34 +01:00
Interpreter: improve split_line
This commit is contained in:
parent
57630e7c12
commit
8c97a57eab
@ -550,9 +550,11 @@ sub extract_bracketed {
|
|||||||
return ($result, $rest);
|
return ($result, $rest);
|
||||||
}
|
}
|
||||||
|
|
||||||
# splits line into quoted arguments while preserving quotes. handles
|
# splits line into quoted arguments while preserving quotes.
|
||||||
# unbalanced quotes gracefully by treating them as part of the argument
|
# a string is considered quoted only if they are surrounded by
|
||||||
# they were found within.
|
# whitespace or json separators.
|
||||||
|
# handles unbalanced quotes gracefully by treating them as
|
||||||
|
# part of the argument they were found within.
|
||||||
sub split_line {
|
sub split_line {
|
||||||
my ($self, $line, %opts) = @_;
|
my ($self, $line, %opts) = @_;
|
||||||
|
|
||||||
@ -572,6 +574,7 @@ sub split_line {
|
|||||||
my $token = '';
|
my $token = '';
|
||||||
my $ch = ' ';
|
my $ch = ' ';
|
||||||
my $last_ch;
|
my $last_ch;
|
||||||
|
my $next_ch;
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
my $pos;
|
my $pos;
|
||||||
my $ignore_quote = 0;
|
my $ignore_quote = 0;
|
||||||
@ -596,6 +599,7 @@ sub split_line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ch = $chars[$i++];
|
$ch = $chars[$i++];
|
||||||
|
$next_ch = $chars[$i];
|
||||||
|
|
||||||
$spaces = 0 if $ch ne ' ';
|
$spaces = 0 if $ch ne ' ';
|
||||||
|
|
||||||
@ -615,7 +619,7 @@ sub split_line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (defined $quote) {
|
if (defined $quote) {
|
||||||
if ($ch eq $quote) {
|
if ($ch eq $quote and (not defined $next_ch or $next_ch =~ /[\s,:;})\].+=]/)) {
|
||||||
# closing quote
|
# closing quote
|
||||||
$token .= $ch unless $opts{strip_quotes};
|
$token .= $ch unless $opts{strip_quotes};
|
||||||
push @args, $token;
|
push @args, $token;
|
||||||
@ -628,7 +632,7 @@ sub split_line {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($last_ch eq ' ' or $last_ch eq ':' or $last_ch eq '(') and not defined $quote and ($ch eq "'" or $ch eq '"')) {
|
if (($last_ch =~ /[\s:{(\[.+=]/) and not defined $quote and ($ch eq "'" or $ch eq '"')) {
|
||||||
if ($ignore_quote) {
|
if ($ignore_quote) {
|
||||||
# treat unbalanced quote as part of this argument
|
# treat unbalanced quote as part of this argument
|
||||||
$token .= $ch;
|
$token .= $ch;
|
||||||
|
Loading…
Reference in New Issue
Block a user