]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Protect the columns sorting against missing or invalid dates
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 4 Jul 2011 11:55:43 +0000 (11:55 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 4 Jul 2011 11:55:43 +0000 (11:55 +0000)
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

index 837c56c22fc77d3547d42b04dfb382ef7065af5e..604b9e33019035da6cbd74d5efd266460529bfac 100644 (file)
@@ -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<dt2) return -1;
     return 1;
   },
   sort_mmdd: function(a,b) {
     mtch = a[0].match(sorttable.DATE_RE);
-    y = mtch[3]; d = mtch[2]; m = 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]; d = mtch[2]; m = 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]; d = mtch[2]; m = 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]; d = mtch[2]; m = 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<dt2) return -1;
     return 1;