Item1878: Numerical Sort in table columns broken

Priority: Urgent
Current State: Closed
Released In: 1.0.7, 1.1.0
Target Release: patch
Applies To: Extension
Component: TablePlugin
Reported By: FulvioScapin
Waiting For: Main.KennethLavrsen
Last Change By: KennethLavrsen
Trying to sort a table column containing just numbers resulted in a textual sorting in a 1.0.6 installation.

Digging into the code, I managed to restrict the problem to what follows:
  • lib/Foswiki/Plugins/TablePlugin/ calls, in _convertToNumberAndDate, Foswiki::Time::parseTime with each row value as parameter
  • in lib/Foswiki/, parseTime($date) returns 0 for each input value, but the regex at line 162 matches 2-digits numbers as years, and when $date reaches 60, it passes the following code at line 198:
    198         return 0 if ( defined($year) && $year < 60 );
    resulting in parseTime returning -315619200 instead of 0, and therefore breaking the sorting of the column, because the previous column values figured as numbers, and this specific one as a date.

Forcing the regex at line 162 to match exactly 4 digits instead of 2 or more allow the column to be sorted numerically.

Frankly I don't understand how allowing a 2-digit numbrer to match as a date could allow numerical sort to work in any way, given how differentiating between numbers and dates is implemented, but I suspect my understanding to be fairly incomplete.

-- FulvioScapin - 02 Aug 2009

Good analysis

It was a recent fix from June that goofed up normal number sorting.

I am fixing this. I have fix. Just need to update unit test.

-- KennethLavrsen - 02 Sep 2009

Fix checked in. New plugin uploaded. Unit test follows after a good night of sleep.

-- KennethLavrsen - 02 Sep 2009

ItemTemplate edit

Summary Numerical Sort in table columns broken
ReportedBy FulvioScapin
Codebase 1.0.6
SVN Range Foswiki-1.0.0, Thu, 08 Jan 2009, build 1878
AppliesTo Extension
Component TablePlugin
Priority Urgent
CurrentState Closed
WaitingFor KennethLavrsen
Checkins distro:99c1f81501dc distro:601d3f87f861 distro:a70a40b858ff distro:146fffa83152
TargetRelease patch
ReleasedIn 1.0.7, 1.1.0
Topic revision: r8 - 20 Sep 2009, KennethLavrsen - This page was cached on 16 Sep 2021 - 14:16.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy