CakeDC / search

Search Plugin for CakePHP
http://cakedc.com
Other
355 stars 169 forks source link

wildcardOne does not get escaped properly on MSSQL #215

Closed ravage84 closed 8 years ago

ravage84 commented 8 years ago

wildcardOne does not get escaped properly on MSSQL using CakeDC/search 2.5.1.

MySQL uses a backslash to escape, like \_ http://stackoverflow.com/questions/17102043/how-to-escape-underscore-in-the-string-query-in-hibernate-and-sql

ProgreSQL seems to do the same. http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html

But MSSQL (once more :facepunch: ) uses brackets to escape, like [_] http://stackoverflow.com/questions/5821/sql-server-2000-5-escape-an-underscore

This leads to literally interpreted searches, like abc\_def.

The offending lines are: https://github.com/CakeDC/search/blob/2.5.1/Model/Behavior/SearchableBehavior.php#L252 https://github.com/CakeDC/search/blob/2.5.1/Model/Behavior/SearchableBehavior.php#L320

As you see, those lines are almost identical, too. I guess this could be improved by extracting the escaping logic into a separate method or even class.

Megslalk commented 8 years ago

Fix has been merged.