Skip to content
Snippets Groups Projects
Unverified Commit 3eaf4084 authored by colemanw's avatar colemanw Committed by GitHub
Browse files

Merge pull request #21549 from artfulrobot/artfulrobot-htmlencoding-api-output

Add test and fix for API4 failing to decode strings stored as HTML
parents 9a52649a 067dea45
Branches
Tags
No related merge requests found
......@@ -149,6 +149,7 @@ trait DAOActionTrait {
}
$result[] = $this->baoToArray($createResult, $item);
\CRM_Utils_API_HTMLInputCoder::singleton()->decodeRows($result);
}
// Use bulk `writeRecords` method if the BAO doesn't have a create or add method
......
......@@ -34,4 +34,37 @@ class ResultTest extends UnitTestCase {
$this->assertTrue(is_array(json_decode($json)));
}
/**
* Knowing that the db layer HTML-encodes strings, we want to test
* that this ugliness is hidden from us as users of the API.
*
* @see https://issues.civicrm.org/jira/browse/CRM-11532
* @see https://lab.civicrm.org/dev/core/-/issues/1328
*/
public function testNoDataCorruptionThroughEncoding() {
$original = 'hello < you';
$result = Contact::create(FALSE)
->setValues(['display_name' => $original])
->execute()->first();
$this->assertEquals($original, $result['display_name'],
"The value returned from Contact.create is different to the value sent."
);
$result = Contact::update(FALSE)
->addWhere('id', '=', $result['id'])
->setValues(['display_name' => $original])
->execute()->first();
$this->assertEquals($original, $result['display_name'],
"The value returned from Contact.update is different to the value sent."
);
$result = Contact::get(FALSE)
->addWhere('id', '=', $result['id'])
->execute()->first();
$this->assertEquals($original, $result['display_name'],
"The value returned from Contact.get is different to the value sent."
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment