CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • API Contact get fails when search string contains apostrophe
Pages: [1]

Author Topic: API Contact get fails when search string contains apostrophe  (Read 1165 times)

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
API Contact get fails when search string contains apostrophe
September 15, 2012, 04:35:32 am
There seems to be a bug in the Contact get API function. When you pass a parameter that contains an apostrophe (single quote) it fails to find anything.

It's easy to reproduce this on the demo environment: Just go to the API Explorer, select Contact, get, and and a parameter to the query string to search for an existing contact whose name contains an apostrophe, e.g. household_name=Sheila Smith's home. You will get no results. Now replace the apostrophe with a % and you will get the result you should have got before.

When I checked my MySQL log file I found that each apostrophe had been prefixed by three backslashes, e.g. ' becomes \\\'. Each apostrophe should be prefixed by a single backslash, not three backslashes. It seems likely that the API is unnecessarily escaping the search string twice, so ' becomes \' becomes \\\'.

This problem seems specific to the Contact API. Hopefully a fix should be fairly trivial for someone who knows the API code. Shall I create a bug report on the Issue Tracker?

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: API Contact get fails when search string contains apostrophe
September 21, 2012, 02:13:53 am
I have now created an issue CRM-10857. Should I just go ahead and do that in future?

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: API Contact get fails when search string contains apostrophe
September 21, 2012, 05:35:00 am
The recommended procedure is to first ask here, as you did. Not sure why we failed to respond, but anyhow, here is the page about bug reporting in CiviCRM:

http://civicrm.org/bugreporting

Thank you.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API Contact get fails when search string contains apostrophe
September 21, 2012, 06:43:44 am
Hi,

Do you have the same problem if you search using php? ie. might be a bug in the api explorer or ajax query, not in the api itself

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: API Contact get fails when search string contains apostrophe
September 21, 2012, 06:48:27 am
Yes, the same problem occurs when calling the API from PHP.

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: API Contact get fails when search string contains apostrophe
January 10, 2014, 01:31:55 pm
I see that this issue was fixed and I've been able to confirm on my 4.3 installation that it works (i.e. I can search for names with single quotes in them from the api explorer).

I have the same or similar issue when searching a custom field that has a single quote in it - anyone with some insight into whether this is the same or a different problem?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • API Contact get fails when search string contains apostrophe

This forum was archived on 2017-11-26.