vedmack / yadcf

Yet Another DataTables Column Filter (yadcf)
http://yadcf-showcase.appspot.com/
MIT License
732 stars 284 forks source link

0.9.4 throws error if data has apostrophe using select2 #578

Closed louking closed 5 years ago

louking commented 5 years ago

see https://codepen.io/louking/pen/yWRWQK and select New Jersey's using select above table

I saw this in beta 25, but cdn has beta 5 -- this traceback is from beta 5

Uncaught Error: Syntax error, unrecognized expression: option[value='New Jersey's']
    at Function.Sizzle.error (jquery-3.3.1.js:1541)
    at Sizzle.tokenize (jquery-3.3.1.js:2193)
    at Function.Sizzle [as find] (jquery-3.3.1.js:815)
    at jQuery.fn.init.find (jquery-3.3.1.js:2873)
    at appendFilters (jquery.dataTables.yadcf.js:2753)
    at HTMLTableElement.<anonymous> (jquery.dataTables.yadcf.js:3723)
    at HTMLDocument.dispatch (jquery-3.3.1.js:5183)
    at HTMLDocument.elemData.handle (jquery-3.3.1.js:4991)
    at Object.trigger (jquery-3.3.1.js:8249)
    at HTMLTableElement.<anonymous> (jquery-3.3.1.js:8327)
louking commented 5 years ago

Also I think this might be in a couple of places. Search for option[value

vedmack commented 5 years ago

check 0.9.4.beta.27 ,

trf000 commented 5 years ago

I notice this is an issue in the 0.9.3 version. I've got the beta 28 and still get the following:

Uncaught Error: Syntax error, unrecognized expression: Joshuah O'Brien
    at Function.oe.error (jquery-3.3.1.min.js:2)
    at oe.tokenize (jquery-3.3.1.min.js:2)
    at oe.select (jquery-3.3.1.min.js:2)
    at Function.oe [as find] (jquery-3.3.1.min.js:2)
    at w.fn.init.find (jquery-3.3.1.min.js:2)
    at new w.fn.init (jquery-3.3.1.min.js:2)
    at w (jquery-3.3.1.min.js:2)
    at parseTableColumn (jquery.dataTables.yadcf.js:2809)
    at appendFilters (jquery.dataTables.yadcf.js:3081)
    at HTMLTableElement.<anonymous> (jquery.dataTables.yadcf.js:4526)

Also get it if I am not using Select2

trf000 commented 5 years ago

I was able to get this to work by altering two lines, but I'm not certain of the total effect of this. Lines 3323 and 3364 I changed var optionExists = filter.find("option[value='" + tmpStr + "']").length === 1; to var optionExists = filter.find('option[value="' + tmpStr + '"]').length === 1;

this allows content with an apostrophe to go through. For me this works as my filtered content will never contain a quotation mark.

vedmack commented 5 years ago

@trf000 please provide a minimal test page so I can check it / your fix

trf000 commented 5 years ago

@vedmack

https://codepen.io/trf000/pen/qBByyGW

I'd keep both versions of the line, or better yet, some kind of flag to determine which to use on a given filter. I'll never have a case where i am filtering data that containd double quotes, but I will filter names with single quotes on occasion.