From 903b83422228b7309f4da38a675b2507ad6786b9 Mon Sep 17 00:00:00 2001 From: Mottie Date: Tue, 24 Mar 2015 15:08:55 -0500 Subject: [PATCH] Select2 widget: escape forward slashes --- dist/js/widgets/widget-filter-formatter-select2.min.js | 2 +- js/widgets/widget-filter-formatter-select2.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/js/widgets/widget-filter-formatter-select2.min.js b/dist/js/widgets/widget-filter-formatter-select2.min.js index 0972bd9f..32fa26c6 100644 --- a/dist/js/widgets/widget-filter-formatter-select2.min.js +++ b/dist/js/widgets/widget-filter-formatter-select2.min.js @@ -1,4 +1,4 @@ /*! Filter widget select2 formatter function - updated 2/7/2015 (v2.19.0) * requires: jQuery 1.7.2+, tableSorter (FORK) 2.16+, filter widget 2.16+ and select2 v3.4.6+ plugin */ -!function(a){"use strict";var b=a.tablesorter||{};b.filterFormatter=b.filterFormatter||{},b.filterFormatter.select2=function(c,d,e){var f,g,h=a.extend({cellText:"",match:!0,value:"",multiple:!0,width:"100%"},e),i=c.closest("table")[0].config,j=i.widgetOptions,k=a('').appendTo(c).bind("change"+i.namespace+"filter",function(){var a=this.value;a=a.replace(/[/()$^]/g,"").split("|"),c.find(".select2").select2("val",a),q()}),l=i.$headerIndexed[d],m=l.hasClass(j.filter_onlyAvail),n=[],o=h.match?"":"^",p=h.match?"":"$",q=function(){var b=!1,d=c.find(".select2").select2("val")||h.value||"";a.isArray(d)&&(b=!0,d=d.join("\x00")),d=d.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),b&&(d=d.split("\x00")),k.val(a.isArray(d)&&d.length&&""!==d.join("")?"/("+o+(d||[]).join(p+"|"+o)+p+")/":"").trigger("search").end().find(".select2").select2("val",d),n.length&&n.find(".select2").select2("val",d)},r=function(){g=[],f=b.filter.getOptionSource(i.$table[0],d,m)||[],a.each(f,function(a,b){g.push({id:b,text:b})}),h.data=g};return l.toggleClass("filter-match",h.match),h.cellText&&c.prepend(""),h.ajax&&!a.isEmptyObject(h.ajax)||h.data||(r(),m&&i.$table.bind("filterEnd",function(){r(),c.add(n).find(".select2").select2(h)})),a('').val(h.value).appendTo(c).select2(h).bind("change",function(){q()}),i.$table.bind("filterFomatterUpdate",function(){var a=i.$table.data("lastSearch")[d]||"";a=a.replace(/^\/\(\^?/,"").replace(/\$\|\^/g,"|").replace(/\$?\)\/$/g,"").split("|"),c.find(".select2").select2("val",a),q(),b.filter.formatterUpdated(c,d)}),i.$table.bind("stickyHeadersInit",function(){n=i.widgetOptions.$sticky.find(".tablesorter-filter-row").children().eq(d).empty(),a('').val(h.value).appendTo(n).select2(h).bind("change",function(){c.find(".select2").select2("val",n.find(".select2").select2("val")),q()}),h.cellText&&n.prepend("")}),i.$table.bind("filterReset",function(){c.find(".select2").select2("val",h.value||""),setTimeout(function(){q()},0)}),q(),k}}(jQuery); \ No newline at end of file +!function(a){"use strict";var b=a.tablesorter||{};b.filterFormatter=b.filterFormatter||{},b.filterFormatter.select2=function(c,d,e){var f,g,h=a.extend({cellText:"",match:!0,value:"",multiple:!0,width:"100%"},e),i=c.closest("table")[0].config,j=i.widgetOptions,k=a('').appendTo(c).bind("change"+i.namespace+"filter",function(){var a=this.value;a=a.replace(/[/()$^]/g,"").split("|"),c.find(".select2").select2("val",a),q()}),l=i.$headerIndexed[d],m=l.hasClass(j.filter_onlyAvail),n=[],o=h.match?"":"^",p=h.match?"":"$",q=function(){var b=!1,d=c.find(".select2").select2("val")||h.value||"";a.isArray(d)&&(b=!0,d=d.join("\x00")),d=d.replace(/[-[\]{}()*+?.,/\\^$|#\s]/g,"\\$&"),b&&(d=d.split("\x00")),k.val(a.isArray(d)&&d.length&&""!==d.join("")?"/("+o+(d||[]).join(p+"|"+o)+p+")/":"").trigger("search").end().find(".select2").select2("val",d),n.length&&n.find(".select2").select2("val",d)},r=function(){g=[],f=b.filter.getOptionSource(i.$table[0],d,m)||[],a.each(f,function(a,b){g.push({id:b,text:b})}),h.data=g};return l.toggleClass("filter-match",h.match),h.cellText&&c.prepend(""),h.ajax&&!a.isEmptyObject(h.ajax)||h.data||(r(),m&&i.$table.bind("filterEnd",function(){r(),c.add(n).find(".select2").select2(h)})),a('').val(h.value).appendTo(c).select2(h).bind("change",function(){q()}),i.$table.bind("filterFomatterUpdate",function(){var a=i.$table.data("lastSearch")[d]||"";a=a.replace(/^\/\(\^?/,"").replace(/\$\|\^/g,"|").replace(/\$?\)\/$/g,"").split("|"),c.find(".select2").select2("val",a),q(),b.filter.formatterUpdated(c,d)}),i.$table.bind("stickyHeadersInit",function(){n=i.widgetOptions.$sticky.find(".tablesorter-filter-row").children().eq(d).empty(),a('').val(h.value).appendTo(n).select2(h).bind("change",function(){c.find(".select2").select2("val",n.find(".select2").select2("val")),q()}),h.cellText&&n.prepend("")}),i.$table.bind("filterReset",function(){c.find(".select2").select2("val",h.value||""),setTimeout(function(){q()},0)}),q(),k}}(jQuery); \ No newline at end of file diff --git a/js/widgets/widget-filter-formatter-select2.js b/js/widgets/widget-filter-formatter-select2.js index 8556599e..e316d4d6 100644 --- a/js/widgets/widget-filter-formatter-select2.js +++ b/js/widgets/widget-filter-formatter-select2.js @@ -52,7 +52,7 @@ ts.filterFormatter.select2 = function($cell, indx, select2Def) { v = v.join('\u0000'); } // escape special regex characters (http://stackoverflow.com/a/9310752/145346) - v = v.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + v = v.replace(/[-[\]{}()*+?.,/\\^$|#\s]/g, '\\$&'); // convert string back into an array if (arry) { v = v.split('\u0000');