Search string on a custom contact field is escaped too many times
I am having an issue searching for data using a custom field, when the search string contains a ' character.
Steps to reproduce:
- create a new custom fieldset:
- used for: contacts
- create a new field:
- Data and Input Field Type: Alphanumeric Text
- Is this Field Searchable?: checked
- update a contact with some data that needs to be escaped (e.g. "St. Paul's")
- search for the test data using:
- advanced search
- =: no results returned
- search builder
- =, LIKE: no results
- IN: results returned
- apiv3
- =: no results
- LIKE, IN: results returned
- advanced search
We are running the ESR and I am also able to reproduce this on the latest release (5.18.4).
I debugged a bit and found that the search string is being escaped two times in CRM_Core_BAO_CustomQuery (lines 308 and 327 in 5.18.4) and once in CRM_Contact_BAO_Query (line 5654).