Fix split_line issue where it could sometimes forget tokens when encountering unbalanced quotes

This commit is contained in:
Pragmatic Software 2019-07-08 15:51:55 -07:00
parent 83fc8536d0
commit 81ae3a5741
3 changed files with 9 additions and 3 deletions

View File

@ -572,6 +572,7 @@ sub split_line {
my $escaped = 0; my $escaped = 0;
my $quote; my $quote;
my $token = ''; my $token = '';
my $last_token = '';
my $ch = ' '; my $ch = ' ';
my $last_ch; my $last_ch;
my $next_ch; my $next_ch;
@ -590,7 +591,7 @@ sub split_line {
$ignore_quote = 1; $ignore_quote = 1;
$quote = undef; $quote = undef;
$last_ch = ' '; $last_ch = ' ';
$token = ''; $token = $last_token;
} else { } else {
# add final token and exit # add final token and exit
push @args, $token if length $token; push @args, $token if length $token;
@ -641,6 +642,7 @@ sub split_line {
# begin potential quoted argument # begin potential quoted argument
$pos = $i - 1; $pos = $i - 1;
$quote = $ch; $quote = $ch;
$last_token = $token;
$token .= $ch unless $opts{strip_quotes}; $token .= $ch unless $opts{strip_quotes};
} }
next; next;

View File

@ -1040,6 +1040,7 @@ sub split_line {
my $escaped = 0; my $escaped = 0;
my $quote; my $quote;
my $token = ''; my $token = '';
my $last_token = '';
my $ch = ' '; my $ch = ' ';
my $last_ch; my $last_ch;
my $next_ch; my $next_ch;
@ -1058,7 +1059,7 @@ sub split_line {
$ignore_quote = 1; $ignore_quote = 1;
$quote = undef; $quote = undef;
$last_ch = ' '; $last_ch = ' ';
$token = ''; $token = $last_token;
} else { } else {
# add final token and exit # add final token and exit
push @args, $token if length $token; push @args, $token if length $token;
@ -1109,6 +1110,7 @@ sub split_line {
# begin potential quoted argument # begin potential quoted argument
$pos = $i - 1; $pos = $i - 1;
$quote = $ch; $quote = $ch;
$last_token = $token;
$token .= $ch unless $opts{strip_quotes}; $token .= $ch unless $opts{strip_quotes};
} }
next; next;

View File

@ -103,6 +103,7 @@ sub split_line {
my $escaped = 0; my $escaped = 0;
my $quote; my $quote;
my $token = ''; my $token = '';
my $last_token = '';
my $ch = ' '; my $ch = ' ';
my $last_ch; my $last_ch;
my $next_ch; my $next_ch;
@ -121,7 +122,7 @@ sub split_line {
$ignore_quote = 1; $ignore_quote = 1;
$quote = undef; $quote = undef;
$last_ch = ' '; $last_ch = ' ';
$token = ''; $token = $last_token;
} else { } else {
# add final token and exit # add final token and exit
push @args, $token if length $token; push @args, $token if length $token;
@ -172,6 +173,7 @@ sub split_line {
# begin potential quoted argument # begin potential quoted argument
$pos = $i - 1; $pos = $i - 1;
$quote = $ch; $quote = $ch;
$last_token = $token;
$token .= $ch unless $opts{strip_quotes}; $token .= $ch unless $opts{strip_quotes};
} }
next; next;