From: Thomas Schüttler Date: Fri, 19 Mar 2021 11:25:34 +0000 (+0100) Subject: Drop HTML markup in exports for link custom fields X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=319a89b544c3e42b330be6ebeb5509c896c522ae;p=civicrm-core.git Drop HTML markup in exports for link custom fields --- diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 3ba681e456..c3b0dd24bf 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -1120,6 +1120,11 @@ class CRM_Export_BAO_ExportProcessor { return $result['values'][$result['id']]['url']; } + // Do not export HTML markup for links + if ($html_type === 'Link' && $fieldValue) { + return $fieldValue; + } + return CRM_Core_BAO_CustomField::displayValue($fieldValue, $cfID); } elseif (in_array($field, [ diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 99d699ca6c..c35ce4bebe 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -734,6 +734,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $longString .= 'Blah'; } $this->addOptionToCustomField('select_string', ['label' => $longString, 'name' => 'blah']); + $longUrl = 'https://stage.example.org/system/files/webform/way_too_long_url_that_still_fits_in_a_link_custom_field_but_would_fail_to_export_with_html.jpg'; $this->callAPISuccess('Contact', 'create', [ 'id' => $this->contactIDs[1], @@ -741,12 +742,14 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $this->getCustomFieldName('country') => 'LA', $this->getCustomFieldName('select_string') => 'blah', 'api.Address.create' => ['location_type_id' => 'Billing', 'city' => 'Waipu'], + $this->getCustomFieldName('link') => $longUrl, ]); $selectedFields = [ ['name' => 'city', 'location_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Address', 'location_type_id', 'Billing')], ['name' => $this->getCustomFieldName('text')], ['name' => $this->getCustomFieldName('country')], ['name' => $this->getCustomFieldName('select_string')], + ['name' => $this->getCustomFieldName('link')], ]; $this->doExportTest([ @@ -758,6 +761,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $this->assertEquals('Waipu', $row['Billing-City']); $this->assertEquals("Lao People's Democratic Republic", $row['Country']); $this->assertEquals($longString, $row['Pick Color']); + $this->assertEquals($longUrl, $row['test_link']); } /**