From 2ef1d246dfb6eefab14cd811b8acb530ade9673b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Mon, 4 Jul 2011 11:55:43 +0000 Subject: [PATCH] Protect the columns sorting against missing or invalid dates Sorttable.js fails on columns containing a date on the first row but not on subsequent rows. This patch assumes a zero date for any missing or invalid date sorting those rows at the top of the table. --- sorttable/sorttable.js | 48 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/sorttable/sorttable.js b/sorttable/sorttable.js index 837c56c..604b9e3 100644 --- a/sorttable/sorttable.js +++ b/sorttable/sorttable.js @@ -268,30 +268,46 @@ sorttable = { }, sort_ddmm: function(a,b) { mtch = a[0].match(sorttable.DATE_RE); - y = mtch[3]; m = mtch[2]; d = mtch[1]; - if (m.length == 1) m = '0'+m; - if (d.length == 1) d = '0'+d; - dt1 = y+m+d; + if (mtch) { + y = mtch[3]; m = mtch[2]; d = mtch[1]; + if (m.length == 1) m = '0'+m; + if (d.length == 1) d = '0'+d; + dt1 = y+m+d; + } else { + dt1 = "00000000"; + } mtch = b[0].match(sorttable.DATE_RE); - y = mtch[3]; m = mtch[2]; d = mtch[1]; - if (m.length == 1) m = '0'+m; - if (d.length == 1) d = '0'+d; - dt2 = y+m+d; + if (mtch) { + y = mtch[3]; m = mtch[2]; d = mtch[1]; + if (m.length == 1) m = '0'+m; + if (d.length == 1) d = '0'+d; + dt2 = y+m+d; + } else { + dt2 = "00000000"; + } if (dt1==dt2) return 0; if (dt1