From: Eileen McNaughton Date: Fri, 11 Apr 2014 05:14:47 +0000 (+1200) Subject: CRM-14459 fix for fatal error on bad street parsing X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=689cecfd0a41cff81ade7ea77c16da6764fbe85d;p=civicrm-core.git CRM-14459 fix for fatal error on bad street parsing --- diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 40785fcb78..5285d7811c 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -768,7 +768,7 @@ ORDER BY civicrm_address.is_primary DESC, civicrm_address.location_type_id DESC, CRM_Core_Session::setStatus(ts('Unsupported locale specified to parseStreetAddress: %1. Proceeding with en_US locale.', array(1 => $locale)), ts('Unsupported Locale'), 'alert'); $locale = 'en_US'; } - $parseFields = array( + $emptyParseFields = $parseFields = array( 'street_name' => '', 'street_unit' => '', 'street_number' => '', @@ -844,7 +844,8 @@ ORDER BY civicrm_address.is_primary DESC, civicrm_address.location_type_id DESC, 'en_CA', 'fr_CA'))) { $streetUnitFormats = array('APT', 'APP', 'SUITE', 'BUREAU', 'UNIT'); } - + //@todo per CRM-14459 this regex picks up words with the string in them - e.g APT picks up + //Captain - presuming fixing regex (& adding test) to ensure a-z does not preced string will fix $streetUnitPreg = '/(' . implode('|\s', $streetUnitFormats) . ')(.+)?/i'; $matches = array(); if (preg_match($streetUnitPreg, $streetAddress, $matches)) { @@ -860,6 +861,14 @@ ORDER BY civicrm_address.is_primary DESC, civicrm_address.location_type_id DESC, foreach ($parseFields as $parseField => $value) { $parseFields[$parseField] = CRM_Utils_String::stripSpaces($value); } + //CRM-14459 if the field is too long we should assume it didn't get it right & skip rather than allow + // the DB to fatal + $fields = CRM_Core_BAO_Address::fields(); + foreach ($fields as $fieldname => $field) { + if(!empty($field['maxlength']) && strlen(CRM_Utils_Array::value($fieldname, $parseFields)) > $field['maxlength']) { + return $emptyParseFields; + } + } return $parseFields; }