mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-10-21 23:28:19 +00:00
fix(tabutils): refuse a tabrestore row with a field after the last column
tabrestore stripped the comma after each field, so a comma after the field of the last column left nothing to report. A row with one more empty field was restored as if it fit the columns. A last extra field of 0 also passed, because the check tested the rest of the line for truth. tabrestore now refuses a row whose last column field ends with a comma, or that has any text left, and rolls back the restore.
This commit is contained in:
@@ -430,6 +430,7 @@ sub tabrestore
|
||||
my $origline = $line; #save for error reporting
|
||||
my %record;
|
||||
my $col;
|
||||
my $separated; #a comma after the field of the last column starts one more field
|
||||
foreach $col (@colns)
|
||||
{
|
||||
if ($line =~ /^,/ or $line eq "")
|
||||
@@ -438,7 +439,7 @@ sub tabrestore
|
||||
if (!exists($auto_cols{$col})) {
|
||||
$record{$col} = undef;
|
||||
}
|
||||
$line =~ s/^,//;
|
||||
$separated = ($line =~ s/^,//);
|
||||
}
|
||||
elsif ($line =~ /^[^,]*"/)
|
||||
{ # We have stuff in quotes... pain...
|
||||
@@ -501,7 +502,7 @@ sub tabrestore
|
||||
elsif ($offset eq length($line) or $nextchar eq ',')
|
||||
{ #hit the end of the line or at least the end of the column
|
||||
$ent = substr($line, 0, $offset, '');
|
||||
$line =~ s/^,//;
|
||||
$separated = ($line =~ s/^,//);
|
||||
chop $ent;
|
||||
$ent = substr($ent, 1);
|
||||
$ent =~ s/""/"/g;
|
||||
@@ -531,10 +532,10 @@ sub tabrestore
|
||||
{
|
||||
$record{$col} = $1;
|
||||
}
|
||||
$line =~ s/^([^,]+)(,|$)//;
|
||||
$separated = ($line =~ s/^([^,]+)(,|$)//) && $2 eq ',';
|
||||
}
|
||||
}
|
||||
if ($line)
|
||||
if ($line ne '' or $separated)
|
||||
{
|
||||
$rollback = 1;
|
||||
$cb->({ error => "Too many fields on line $linenumber: $origline | $line", errorcode => 4 });
|
||||
|
||||
Reference in New Issue
Block a user