replace quotes in filter select - fixes #242

This commit is contained in:
Mottie 2013-02-21 07:31:58 -06:00
parent 220f1c580c
commit 4e2887e22f

View File

@ -306,15 +306,14 @@ $.tablesorter.addWidget({
$t = $(table).addClass('hasFilters'),
b = c.$tbodies,
cols = c.parsers.length,
reg = [ // regex used in filter "check" functions
/^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/, // 0 = regex to test for regex
new RegExp(c.cssChildRow), // 1 = child row
/undefined|number/, // 2 = check type
/(^[\"|\'|=])|([\"|\'|=]$)/, // 3 = exact match
/[\"\'=]/g, // 4 = replace exact match flags
/[^\w,. \-()]/g, // 5 = replace non-digits (from digit & currency parser)
/[<>=]/g // 6 = replace operators
],
reg = { // regex used in filter "check" functions
"regex" : /^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/, // regex to test for regex
"child" : new RegExp(c.cssChildRow), // child row
"type" : /undefined|number/, // check type
"exact" : /(^[\"|\'|=])|([\"|\'|=]$)/g, // exact match
"nondigit" : /[^\w,. \-()]/g, // replace non-digits (from digit & currency parser)
"operators" : /[<>=]/g // replace operators
},
parsed, time, timer,
// dig fer gold
@ -366,7 +365,7 @@ $.tablesorter.addWidget({
// loop through the rows
for (j = 0; j < l; j++){
// skip child rows
if (reg[1].test($tr[j].className)) { continue; }
if (reg["child"].test($tr[j].className)) { continue; }
r = true;
cr = $tr.eq(j).nextUntil('tr:not(.' + c.cssChildRow + ')');
// so, if "table.config.widgetOptions.filter_childRows" is true and there is
@ -386,7 +385,7 @@ $.tablesorter.addWidget({
// using older or original tablesorter
x = $.trim($td.eq(i).text());
}
xi = !reg[2].test(typeof x) && wo.filter_ignoreCase ? x.toLocaleLowerCase() : x;
xi = !reg["type"].test(typeof x) && wo.filter_ignoreCase ? x.toLocaleLowerCase() : x;
ff = r; // if r is true, show that row
// val = case insensitive, v[i] = case sensitive
val = wo.filter_ignoreCase ? v[i].toLocaleLowerCase() : v[i];
@ -402,8 +401,8 @@ $.tablesorter.addWidget({
ff = wo.filter_functions[i][v[i]](x, c.cache[k].normalized[j][i], v[i], i);
}
// Look for regex
} else if (reg[0].test(val)){
rg = reg[0].exec(val);
} else if (reg["regex"].test(val)){
rg = reg["regex"].exec(val);
try {
ff = new RegExp(rg[1], rg[2]).test(xi);
} catch (err){
@ -411,7 +410,7 @@ $.tablesorter.addWidget({
}
// Look for quotes or equals to get an exact match; ignore type since xi could be numeric
/*jshint eqeqeq:false */
} else if (reg[3].test(val) && xi == val.replace(reg[4], '')){
} else if (reg["exact"].test(val) && xi == val.replace(reg["exact"], '')){
ff = true;
// Look for a not match
} else if (/^\!/.test(val)){
@ -421,8 +420,8 @@ $.tablesorter.addWidget({
// Look for operators >, >=, < or <=
} else if (/^[<>]=?/.test(val)){
// xi may be numeric - see issue #149
rg = isNaN(xi) ? fmt(xi.replace(reg[5], ''), table) : fmt(xi, table);
s = fmt(val.replace(reg[5], '').replace(reg[6],''), table);
rg = isNaN(xi) ? fmt(xi.replace(reg["nondigit"], ''), table) : fmt(xi, table);
s = fmt(val.replace(reg["nondigit"], '').replace(reg["operators"],''), table);
if (/>/.test(val)) { ff = />=/.test(val) ? rg >= s : rg > s; }
if (/</.test(val)) { ff = /<=/.test(val) ? rg <= s : rg < s; }
if (s === '') { ff = true; } // keep showing all rows if nothing follows the operator
@ -437,10 +436,10 @@ $.tablesorter.addWidget({
}
// Look for a range (using " to " or " - ") - see issue #166; thanks matzhu!
} else if (/\s+(-|to)\s+/.test(val)){
rg = isNaN(xi) ? fmt(xi.replace(reg[5], ''), table) : fmt(xi, table);
rg = isNaN(xi) ? fmt(xi.replace(reg["nondigit"], ''), table) : fmt(xi, table);
s = val.split(/(?: - | to )/); // make sure the dash is for a range and not indicating a negative number
r1 = fmt(s[0].replace(reg[5], ''), table);
r2 = fmt(s[1].replace(reg[5], ''), table);
r1 = fmt(s[0].replace(reg["nondigit"], ''), table);
r2 = fmt(s[1].replace(reg["nondigit"], ''), table);
if (r1 > r2) { ff = r1; r1 = r2; r2 = ff; } // swap
ff = (rg >= r1 && rg <= r2) || (r1 === '' || r2 === '') ? true : false;
// Look for wild card: ? = single, * = multiple, or | = logical OR
@ -499,7 +498,8 @@ $.tablesorter.addWidget({
// build option list
for (k = 0; k < arry.length; k++){
o += '<option value="' + arry[k] + '">' + arry[k] + '</option>';
// replace quotes - fixes #242
o += '<option value="' + arry[k].replace(/\"/g, "&quot;") + '">' + arry[k] + '</option>';
}
$t.find('thead').find('select.' + css + '[data-column="' + i + '"]')[ updating ? 'html' : 'append' ](o);
},