Drop HTML markup in exports for link custom fields
authorThomas Schüttler <tschuettler@oxfam.de>
Fri, 19 Mar 2021 11:25:34 +0000 (12:25 +0100)
committerThomas Schüttler <tschuettler@oxfam.de>
Fri, 19 Mar 2021 11:25:34 +0000 (12:25 +0100)
CRM/Export/BAO/ExportProcessor.php
tests/phpunit/CRM/Export/BAO/ExportTest.php

index 3ba681e456482c60bb721f2631ba505bd38a345a..c3b0dd24bf6c4e428039ba1e66ec544d9e6f9b50 100644 (file)
@@ -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, [
index 99d699ca6cb718ebc454e16c29ee00ac31810c35..c35ce4bebe49da0de2fa9f0da54ce41d9e09408b 100644 (file)
@@ -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']);
   }
 
   /**