Full fix for the api v2
CRM-13554 - Improve string validation in the query engine
Backport of https://github.com/civicrm/civicrm-core/pull/1758
CRM-13550 improve handling of options

CRM-13550 fix previous