Followup r86088, r87244, r90612: fix jquery.tablesorter for null collation table...
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 22 Jun 2011 23:19:00 +0000 (23:19 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 22 Jun 2011 23:19:00 +0000 (23:19 +0000)
Attempt to build a regex from an empty list failed when calling new RegEx('[]', 'ig') on IE 6/7/8.
Now allowing null for the object, and also not trying to create the regex even if we have an empty object just in case.

resources/jquery/jquery.tablesorter.js

index b443eb1..f12ee0d 100644 (file)
                                // We allow a trailing percent sign, which we just strip.  This works fine
                                // if percents and regular numbers aren't being mixed.
                                ts.numberRegex = new RegExp("^(" + "[-+\u2212]?[0-9][0-9,]*(\\.[0-9,]*)?(E[-+\u2212]?[0-9][0-9,]*)?" + // Fortran-style scientific
-                               "|" + "[-+\u2212]?" + digitClass + "+[\\s\\xa0]*%?" + // Generic localised
+                               "|" + "[-+\u2212]?" + digitClass + "+[\\s]*%?" + // Generic localised
                                ")$", "i");
                        }
 
 
                        function buildCollationTable() {
                                ts.collationTable = mw.config.get('tableSorterCollation');
-                               if ( typeof ts.collationTable === "object" ) {
-                                       ts.collationRegex = [];
+                               ts.collationRegex = null;
+                               if ( ts.collationTable ) {
+                                       var keys = [];
 
                                        //Build array of key names
                                        for ( var key in ts.collationTable ) {
                                                if ( ts.collationTable.hasOwnProperty(key) ) { //to be safe
-                                                       ts.collationRegex.push(key);
+                                                       keys.push(key);
                                                }
                                        }
-                                       ts.collationRegex = new RegExp( '[' + ts.collationRegex.join('') + ']', 'ig' );
+                                       if (keys.length) {
+                                               ts.collationRegex = new RegExp( '[' + ts.collationRegex.join('') + ']', 'ig' );
+                                       }
                                }
                        }