Skip to content

Commit

Permalink
Item9374: EditTablePlugin wrongly assumes that 4 digit numbers is a year
Browse files Browse the repository at this point in the history
TablePlugin was made to be a little too smart and interpreted 4 digit numbers
as dates. That took me 2 hours of fighting before I found out that my 4
digit change request numbers were seen as dates.
Mixing date formats is smart. But we cannot see 4 digit numbers as dates.
I have fixed the problem and also added additional unit test to avoid that
the problem comes back


git-svn-id: http://svn.foswiki.org/trunk@8276 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Jul 22, 2010
1 parent 3312b12 commit 438b9e8
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TablePlugin/lib/Foswiki/Plugins/TablePlugin/Core.pm
Expand Up @@ -447,7 +447,7 @@ sub _convertStringToDate {

my $date = undef;

if ( $text =~ /^\s*-?[0-9]+(\.[0-9])*\s*$/ && $text !~ /^\s*(-*\d{4})\s*$/ )
if ( $text =~ /^\s*-?[0-9]+(\.[0-9])*\s*$/ )
{
_debug("\t this is a number");
}
Expand Down
89 changes: 85 additions & 4 deletions TablePlugin/test/unit/TablePlugin/TablePluginTests.pm
Expand Up @@ -557,6 +557,9 @@ EXPECTED
Test sorting of a numbers column that contains an empty cell and a cell with a string.
Note that we cannot interpret 4 digit numbers as dates because thet goofs up normal number
sorting of 4 digit numbers that have nothing to do with dates (Item9374)
=cut

sub test_sort_dates {
Expand All @@ -577,7 +580,7 @@ sub test_sort_dates {
| 2001-12-29 - 23:59 |
| 2009-1-12 |
| 2009-1 |
| 2009 |
| 2009-2 |
| 2001-12-25T23:59:59 |
| 2001-12-24T |
| 2001-12-22T23:59:59+01:00 |
Expand Down Expand Up @@ -668,20 +671,98 @@ ACTUAL
<td rowspan="1" class="foswikiTableCol0 foswikiSortedAscendingCol foswikiSortedCol foswikiFirstCol foswikiLastCol"> 2001-12-31 23:59 </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td rowspan="1" class="foswikiTableCol0 foswikiSortedAscendingCol foswikiSortedCol foswikiFirstCol foswikiLastCol"> 2009 </td>
<td rowspan="1" class="foswikiTableCol0 foswikiSortedAscendingCol foswikiSortedCol foswikiFirstCol foswikiLastCol"> 2009-1 </td>
</tr>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted1 foswikiTableRowdataBg1">
<td rowspan="1" class="foswikiTableCol0 foswikiSortedAscendingCol foswikiSortedCol foswikiFirstCol foswikiLastCol"> 2009-1 </td>
<td rowspan="1" class="foswikiTableCol0 foswikiSortedAscendingCol foswikiSortedCol foswikiFirstCol foswikiLastCol"> 2009-1-12 </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td rowspan="1" class="foswikiTableCol0 foswikiSortedAscendingCol foswikiSortedCol foswikiFirstCol foswikiLastCol foswikiLast"> 2009-1-12 </td>
<td rowspan="1" class="foswikiTableCol0 foswikiSortedAscendingCol foswikiSortedCol foswikiFirstCol foswikiLastCol foswikiLast"> 2009-2 </td>
</tr>
</tbody></table>
EXPECTED

$this->do_test( $expected, $actual );
}

=pod
Test sorting of 4 digit numbers making sure they are not misinterpreted as dates (Item9374)
=cut

sub test_sort_4_digit_numbers {
my $this = shift;

my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );
my $pubUrlSystemWeb = Foswiki::Func::getPubUrlPath() . '/System';

my $actual = <<ACTUAL;
%TABLE{initsort="3" initdirection="down"}%
| *Title* | *Date* | *Size* | *Span date* |
| ABC | 26 May 2007 - 22:36 | 1704 | <span class="foswikiNoBreak">26 May 2007 - 22:36</span> |
| def | 07 Feb 2006 - 13:23 | 1009 | <span class="foswikiNoBreak">07 Feb 2006 - 13:23</span> |
| GHI | 26 Jul 2007 - 13:23 | 0735 | <span class="foswikiNoBreak">26 Jul 2007 - 13:23</span> |
| jkl| 16 Sep 2008 - 09:48 | 2002 | <span class="foswikiNoBreak">16 Sep 2008 - 09:48</span> |
| MNO | 06 Feb 2006 - 19:02 | 1209 | <span class="foswikiNoBreak">06 Feb 2006 - 19:02</span> |
ACTUAL

my $expected = <<EXPECTED;
<nop>
<nop>
<nop>
<nop>
<nop>
<nop>
<nop>
<table rules="none" border="1" class="foswikiTable" id="table$this->{test_topic}$tableCount">
<thead>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" rel="nofollow">Title</a> </th>
<th class="foswikiTableCol1"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" rel="nofollow">Date</a> </th>
<th class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=2;table=$tableCount;up=1#sorted_table" rel="nofollow">Size</a><span class="tableSortIcon tableSortUp"><img width="11" height="13" border="0" title="Sorted ascending" src="$pubUrlSystemWeb/DocumentGraphics/tablesortup.gif" alt="Sorted ascending"/></span> </th>
<th class="foswikiTableCol3 foswikiLastCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=3;table=$tableCount;up=0#sorted_table" rel="nofollow">Span date</a> </th>
</tr>
</thead>
<tbody>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td class="foswikiTableCol0 foswikiFirstCol" rowspan="1"> GHI </td>
<td class="foswikiTableCol1" rowspan="1"> 26 Jul 2007 - 13:23 </td>
<td class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol" rowspan="1"> 0735 </td>
<td class="foswikiTableCol3 foswikiLastCol" rowspan="1"> <span class="foswikiNoBreak">26 Jul 2007 - 13:23</span> </td>
</tr>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted1 foswikiTableRowdataBg1">
<td class="foswikiTableCol0 foswikiFirstCol" rowspan="1"> def </td>
<td class="foswikiTableCol1" rowspan="1"> 07 Feb 2006 - 13:23 </td>
<td class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol" rowspan="1"> 1009 </td>
<td class="foswikiTableCol3 foswikiLastCol" rowspan="1"> <span class="foswikiNoBreak">07 Feb 2006 - 13:23</span> </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td class="foswikiTableCol0 foswikiFirstCol" rowspan="1"> MNO </td>
<td class="foswikiTableCol1" rowspan="1"> 06 Feb 2006 - 19:02 </td>
<td class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol" rowspan="1"> 1209 </td>
<td class="foswikiTableCol3 foswikiLastCol" rowspan="1"> <span class="foswikiNoBreak">06 Feb 2006 - 19:02</span> </td>
</tr>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted1 foswikiTableRowdataBg1">
<td class="foswikiTableCol0 foswikiFirstCol" rowspan="1"> ABC </td>
<td class="foswikiTableCol1" rowspan="1"> 26 May 2007 - 22:36 </td>
<td class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol" rowspan="1"> 1704 </td>
<td class="foswikiTableCol3 foswikiLastCol" rowspan="1"> <span class="foswikiNoBreak">26 May 2007 - 22:36</span> </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td class="foswikiTableCol0 foswikiFirstCol foswikiLast" rowspan="1"> jkl </td>
<td class="foswikiTableCol1 foswikiLast" rowspan="1"> 16 Sep 2008 - 09:48 </td>
<td class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol foswikiLast" rowspan="1"> 2002 </td>
<td class="foswikiTableCol3 foswikiLastCol foswikiLast" rowspan="1"> <span class="foswikiNoBreak">16 Sep 2008 - 09:48</span> </td>
</tr>
</tbody></table>
EXPECTED

$this->do_test( $expected, $actual );
}


=pod
Test sorting of Date column with HTML tags before the date
Expand Down

0 comments on commit 438b9e8

Please sign in to comment.