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