diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index 5814795c..c254852d 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -550,9 +550,11 @@ sub extract_bracketed { return ($result, $rest); } -# splits line into quoted arguments while preserving quotes. handles -# unbalanced quotes gracefully by treating them as part of the argument -# they were found within. +# splits line into quoted arguments while preserving quotes. +# a string is considered quoted only if they are surrounded by +# whitespace or json separators. +# handles unbalanced quotes gracefully by treating them as +# part of the argument they were found within. sub split_line { my ($self, $line, %opts) = @_; @@ -572,6 +574,7 @@ sub split_line { my $token = ''; my $ch = ' '; my $last_ch; + my $next_ch; my $i = 0; my $pos; my $ignore_quote = 0; @@ -596,6 +599,7 @@ sub split_line { } $ch = $chars[$i++]; + $next_ch = $chars[$i]; $spaces = 0 if $ch ne ' '; @@ -615,7 +619,7 @@ sub split_line { } if (defined $quote) { - if ($ch eq $quote) { + if ($ch eq $quote and (not defined $next_ch or $next_ch =~ /[\s,:;})\].+=]/)) { # closing quote $token .= $ch unless $opts{strip_quotes}; push @args, $token; @@ -628,7 +632,7 @@ sub split_line { 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) { # treat unbalanced quote as part of this argument $token .= $ch;