Skip to content

Commit

Permalink
Item12953: an empty table with a header row was crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
crawford committed Nov 4, 2014
1 parent 32f1552 commit 9d3c595
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
5 changes: 3 additions & 2 deletions EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/TableRow.pm
Expand Up @@ -68,8 +68,9 @@ sub setRow {
my @cell = Foswiki::Tables::Parser::split_cell($val);
$val = \@cell;
}
push(
@{ $this->{cols} },

# Use pushCell so the cell gets numbered
$this->pushCell(
Foswiki::Plugins::EditRowPlugin::TableCell->new( $this, @$val )
);
}
Expand Down
54 changes: 54 additions & 0 deletions EditRowPlugin/test/unit/EditRowPlugin/EditRowPluginSuite.pm
Expand Up @@ -157,6 +157,60 @@ EXPECTED
$this->assert_deep_equals( $e_celldata, $a_celldata );
}

sub test_Item12953 {
my $this = shift;
require Foswiki::Plugins::EditRowPlugin::View;
$this->assert( !$@, $@ );
$this->{test_topicObject}->finish() if $this->{test_topicObject};
$this->{session}->finish() if $this->{session};
my $query = Unit::Request->new( {} );
$this->{session} =
Foswiki->new( $this->{test_user_login}, $query, { view => 1 } );
( $this->{test_topicObject} ) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );

my $in = <<INPUT;
%EDITTABLE{
format="| row,1 | text,20,init |"
header="|*Nr*|*Text*|"
}%
INPUT
$this->assert(
Foswiki::Plugins::EditRowPlugin::View::process(
$in, $this->{test_web},
$this->{test_topic}, $this->{test_topicObject}
)
);
$this->assert( $in =~ s/<!-- STARTINCLUDE.*?-->\s*(.*)\s*<!--.*/$1/s, $in );

$this->assert( $in =~ s/^(<form[^>]*>)\s*(.*?)<\/form>$/$2/s, $in );

my $f = $1;
$f =~ s/action=(["']).*?\1/action="valid"/;
$this->assert_html_equals( <<HTML, "$f</form>" );
<form method="post" action="valid" enctype="multipart/form-data" name="erp_form_EDITTABLE_0"></form>
HTML

# anchor
$this->assert( $in =~ s/^<a name='erp_EDITTABLE_0'><\/a>\s*//s, $in );

# edit button
$this->assert( $in =~ s/(<a name='erp_EDITTABLE_0'>.*)$//s, $in );
my $viewurl = Foswiki::Func::getScriptUrl(
$this->{test_web}, $this->{test_topic}, "view",
erp_topic => "$this->{test_web}.$this->{test_topic}",
erp_table => "EDITTABLE_0",
erp_row => -1,
'#' => "erp_EDITTABLE_0"
);
my $expected = <<EXPECTED;
<a name='erp_EDITTABLE_0'></a><a href='$viewurl' title='Edit full table'><img name="erp_edit_EDITTABLE_0" title="Edit full table" border="0" src="%PUBURLPATH%/%SYSTEMWEB%/EditRowPlugin/edittable.png" /></a><br />
EXPECTED
$this->assert_html_equals( $expected, $1 );
$in =~ s/&quot;1_\d+&quot;/&quot;VERSION&quot;/gs;
$in =~ s/version=1_\d+/version=VERSION/gs;
}

# Default is JS preferred
sub test_edit_view_default {
my $this = shift;
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Tables/Cell.pm
Expand Up @@ -55,9 +55,9 @@ sub new {
---++ ObjectMethod number([$set]) -> $number
Setter/getter for the row number. The row number uniquely identifies the row
within the context of a table. The row number is undef until it is set by
some external agency (e.g. the table)
Setter/getter for the cell number. The number uniquely identifies the cell
within the context of a row. The cell number is undef until it is set by
some external agency (e.g. the row)
=cut

Expand Down
6 changes: 4 additions & 2 deletions core/lib/Foswiki/Tables/Row.pm
Expand Up @@ -75,11 +75,12 @@ sub cell_class {
}

# PACKAGE PRIVATE ObjectMethod pushCell($cellObject) -> $index
# Add a row to the end of the table.
# Add a cell to the end of the row.
sub pushCell {
my ( $this, $cell ) = @_;

$cell->number( push( @{ $this->{cols} }, $cell ) - 1 );
ASSERT( defined $cell->{number} );
return $cell->number;
}

Expand Down Expand Up @@ -207,7 +208,8 @@ sub setRow {
my @cell = Foswiki::Tables::Parser::split_cell($val);
$val = \@cell;
}
$this->pushCell( $this->cell_class->new( $this, @$val ) );
my $c = $this->cell_class->new( $this, @$val );
$this->pushCell($c);
}
$n++;
}
Expand Down

0 comments on commit 9d3c595

Please sign in to comment.